2016-03-25 23 views

答えて

0

あなたはあなたのように、他のリソースから訪問者のカートのアイテムを取得することはありませんカートのアイテム

$cart = Mage::getModel('checkout/cart')->getQuote(); 
if($cart->getAllItems()): 
    foreach ($cart->getAllItems() as $item): 
    echo $item->getProduct()->getName() 
    endforeach; 
endif; 
+0

カートに関連する情報がありません –

+0

あなたはデータを取得するためにAPIを使用していますか? –

+0

最近のカートアイテムを取得していません。メインのMagento Mageファイルを呼び出して、MagentoのデフォルトAPIを使用していないデータを取得しています。 –

0

を得ることができ、そのブラウザセッションに連動。このためには、取得したいリソースから製品を追加する必要があります。これにはAPIが適しています。私はそれがあなたを助けると思う下のコードを見てください。

error_reporting(E_ALL); 
ini_set('display_errors', '1'); 
include_once 'app/Mage.php'; 
umask(0); 
$initializationCode = 'admin'; 
$initializationType = 'store'; 
Mage::app($initializationCode, $initializationType); 

    /** 
    * This is the path to the V2 wsdl of the magento api 
    **/ 
    $wsdl = 'http://yoursite.com/api/v2_soap/?wsdl=1'; 

    /** 
    * Create the soap client 
    **/ 
    $client = new SoapClient($wsdl, array('trace' => false)); 
    $username = 'mysoapuser'; 
    $password = 'mysoapuserpassword'; 

    /** 
    * For every magento api session, we first need to login. 
    * The returned value is you API session_id which you need to 
    * Pass to every API call you make. 
    **/ 
    $session_id = $client->login($username, $password); 

    /** 
    * The first thing we do is create the Magento shopping cart, or quote 
    * 
    * Here is detailed information and more examples from Magento: 
    * http://www.magentocommerce.com/api/soap/checkout/cart/cart.create.html 
    * 
    * We pass it the session_id from our login call and the store id we want 
    * create the quote for. The returned value will be the quote_id 
    * if it was successful, or nothing with no faults if it fails 
    * 
    **/ 
    $cart = $client->shoppingCartCreate($session_id, '1'); 

    $addAddress = $client->shoppingCartCustomerAddresses(
     $session_id, 
     $cart, 
     array(
      array(
       'mode' => 'shipping', 
       'firstname' => 'Paul', 
       'lastname' => 'Briscoe', 
       'street' => '117 N. 1st St.', 
       'city' => 'Ann Arbor', 
       'region' => 'MI', 
       'postcode' => '48104', 
       'country_id' => 'US', 
       'telephone' => '7345458017', 
       'is_default_shipping' => 1 
      ) 
     ) 
    ); 

     /** 
     * Just make sure to check that the quoteId was returned from the API 
     * Next we are going to start adding products into the new quote. The format is below. 
     * Keep in mind that you could easily loop through an array of order products. 
     * 
     * Note: getExternalOrder() does not actually exist, but if you have an order object 
     * or array of products you can use to get the info you need. 
     **/ 

     $externalOrderProducts = getExternalOrder(); 
     $products = array(); 
     foreach($externalOrderProducts as $product){ 
      $products[] = array(
       'product_id' => $product->getId(), 
       'sku' => $product->getSku(), 
       'qty' => $product->getQty(), 
       'options' => null, 
       'bundle_option' => null, 
       'bundle_option_qty' => null, 
       'links' => null 
      ) 
     } 

     /** 
     * Here make the API call back to Magento to add the product array to the quote 
     * 
     * For more information on this call see: 
     * http://www.magentocommerce.com/api/soap/checkout/cartProduct/cart_product.add.html 
     * 
     * Returns True if the product successfully added to the quote 
     **/ 

     if($addAddress) { 
      $addProduct = $client->shoppingCartProductAdd(
       $session_id, 
       $cart, 
       array($products) 
      ); 
     } else { 
      echo "Address did not add."; 
     } 

     /** 
     * Again, check that the product added successfully and then simply call the Shipping List API 
     * For a list of available shipping methods for this quote. 
     * 
     * For more information on this call see: 
     * http://www.magentocommerce.com/api/soap/checkout/cartShipping/cart_shipping.list.html 
     * 
     **/ 

     if($addProduct) { 
      $shipping = $client->shoppingCartShippingList($session_id, $cart); 
     } else { 
      echo "Product did not add."; 
     } 

     echo "<pre>"; 
     var_dump($shipping); 
     echo "</pre>"; 
// 
関連する問題