8

I have to set shipping method to shopping cart , and i am able to display all the available shipping methods , and I have given valid shipping method as the input parameter to SOAP web service method "shoppingCartShippingMethod" so for this, Is there any need to change configuration at the Magento Admin Panel?

<?php
$proxy = new SoapClient('http://127.0.0.1/magento/index.php/api/v2_soap/?wsdl');

$sessionId = $proxy->login('cats', 'sudhir123');
echo "\nSession Id = ";
var_dump($sessionId);

$cartId = $proxy->shoppingCartCreate($sessionId, '3');
echo "\nCart Id = ";
var_dump($cartId);

$customerData = array(
"firstname" => "testFirstname",
"lastname" => "testLastName",
"email" => "[email protected]",
"mode" => "guest",
"website_id" => "0"
  );
$resultCustomerSet = $proxy->shoppingCartCustomerSet($sessionId, $cartId, $customerData);
echo "\nCustomer Set to Shopping Cart = ";
var_dump($resultCustomerSet);

$customeraddress = $proxy->shoppingCartCustomerAddresses($sessionId,     $cartId, array(array(
'mode' => 'billing',
'firstname' => 'Sudhir',
'lastname' => 'Belagali',
'street' => 'street address',
'city' => 'city',
'region' => 'region',
'postcode' => 'postcode',
'country_id' => 'US',
'telephone' => '123456789',
'is_default_billing' => 1
)));   
echo "\nCustomer Address Set to Shopping Cart = ";
var_dump($customeraddress);

$shoppingcartproduct = $proxy->shoppingCartProductAdd($sessionId,    $cartId, array(array(
'product_id' => '917',
'sku' => 'cricketbat',
'qty' => '5',
'options' => null,
'bundle_option' => null,
'bundle_option_qty' => null,
'links' => null
)));   
echo "\nProduct has been added to cart = ";
var_dump($shoppingcartproduct);


$cartInfo = $proxy->shoppingCartInfo($sessionId, $cartId);
echo "\nCart Information for this Cart Id is ( ".$cartId." )";
var_dump($cartInfo);


$result = $proxy->shoppingCartShippingList($sessionId, $cartId);   
echo "\nAvailable Shipping methods = ";
var_dump($result);
?>

enter image description here

5
  • Try to add a product into the cart
    – mkutyba
    Commented Oct 24, 2015 at 22:30
  • Product can be added to cart , But i am trying soap to check the available shipping methods , it is giving me an Empty array Commented Oct 25, 2015 at 4:08
  • But if you add somethig to cart, are the methods available or still empty?
    – mkutyba
    Commented Oct 25, 2015 at 11:43
  • With nothing in your cart no shipping methods will be displayed if you access the data via the cart framework
    – scrowler
    Commented Oct 25, 2015 at 20:05
  • i have added product information , customer information and customer address information into cart , But still i am unable to set the shipping method to cart Commented Oct 30, 2015 at 12:45

3 Answers 3

1

Try to set the System > Configuration > Shipping Methods > "Show Method if Not Applicable" to Yes from the default "No" in the Magento Admin Panel.

enter image description here

2
  • s sir , it gives us the list of available shipping methods and I still unable to set the shipping method to currently existed cart Commented Oct 27, 2015 at 5:59
  • Please post that as a separate question. Commented Oct 27, 2015 at 7:05
1

Yes even I used to face this problem... Try doing this, it worked in my case:

SOAP REFERENCE - CART.CREATE From create cart, to add product to cart, to set customer to cart, adding address to cart everything, include a paramater named "store_id".. I know it is not properly shown for SOAP v2 for many of the SOAP calls.. But you can take reference from SOAP v1 and add this parameter like this below for all cases:

First of all to get store-id: do the following on the top of your code, I think you might be using this file out of magento environment keeping it in the root directory of magento..

require_once ("app/Mage.php");

umask(0);

Mage::app();

$url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

session_start();

Mage::getSingleton("core/session", array("name" => "frontend"));

$storeid = Mage::app()->getStore()->getStoreId();

Now use this store-id to in following calls like this:

$result = $proxy->shoppingCartCreate($sessionId,$storeid);

$result = $proxy->shoppingCartProductAdd($sessionId, $quote_id, array(array( 'product_id' => $product_id, 'sku' => $sku, 'qty' => $qty, 'options' => null, )),$storeid);

$resultCustomerSet = $proxy->shoppingCartCustomerSet($sessionId, $result, $customerData,$storeid);

$result = $client->shoppingCartCustomerAddresses($session, $cart_id, $address,$storeid);

Now try to make this call :

$result = $client->shoppingCartShippingList($session, $cart_id,$storeid);

I am sure it will return you the shipping addresses.

Also, make sure you give same country in your address for which you have kept the shipping method enabled.

0

Try this

// get list of shipping methods

$resultShippingMethods = $proxy->shoppingCartShippingList($sessionId, array($shoppingCartId))

// set shipping method

$randShippingMethodIndex = rand(0, count($resultShippingMethods)-1 );
$shippingMethod = $resultShippingMethods[$randShippingMethodIndex]["code"];

$resultShippingMethod = $proxy->shoppingCartShippingMethod($sessionId,  array($shoppingCartId), $shippingMethod);
3
  • S sir I tried this , But didnt worked for me Commented Nov 1, 2015 at 12:56
  • If you make a checkout normally, the shipping method is showing? Commented Nov 1, 2015 at 16:13
  • It is showing me in the website only,, But not showing me through SOAP call Commented Nov 1, 2015 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.