2017-06-04 3 views
0

I need to get the currently products in cart to estimate how many products are in ? I used the below code but it gave me this error message > Fatal error: Call to undefined method Mage_Sales_Model_Resource_Quote_Item_Collection::getAllItems()Magentoでカート内の現在の製品を取得するには?

Code:

<?php 

     require 'app/Mage.php'; 
     Mage::app(); 

    if (!Mage::isInstalled()) { 
     echo "Application is not installed yet, please complete install wizard first."; 

} 

    $cart =Mage::getSingleton('checkout/cart')->getQuote()->getItemsCollection(); 
      foreach ($cart->getAllItems() as $item) { 
        $productName = $item->getProduct()->getName(); 
        $productPrice = $item->getProduct()->getPrice(); 

      print($item); 


} 

答えて

0

最良の方法は、単にコードの下に使用し、その後Magentoの管理者からのAPIのユーザとパスワードを作成していることについては。

$userName = 'API USER'; 
$key = 'API KEY'; 
$userId = 'USER ID'; 

$client = new SoapClient(Mage::getBaseUrl().'api/soap/?wsdl'); 
$session = $client->login($userName, $key); 

$customer = Mage::getModel('customer/customer')->load($userId); 
$quote = Mage::getSingleton('sales/quote')->loadByCustomer($customer); 
$quoteId = $quote->getId(); 

$cartInfo = $client->call($session, 'cart.info', $quoteId); 
foreach($cartInfo['items'] as $i=>$item) 
{ 
    echo $item['product_id']; 
    echo $item['sku']; 
} 
0

あなたのコードに問題があります:

$cart =Mage::getSingleton('checkout/cart')->getQuote()->getItemsCollection(); 

は、それは次のようになります。

$cart = Mage::getSingleton('checkout/cart'); 
$quote = $cart->getQuote(); 
foreach ($quote->getAllItems() as $item) { 
     $productName = $item->getProduct()->getName(); 
     $productPrice = $item->getProduct()->getPrice(); 

     print($item); 
} 
関連する問題