Как получить элементы корзины по идентификатору клиента / электронной почте на стороне администратора в Magento?

Мне нужно отобразить сетку на стороне администратора со списком продуктов корзины, которые еще не заказаны для всех клиентов. т.е. я хочу отображать цитаты клиентов. Я попробовал приведенный ниже код, но результаты возвращают что-то не связанное с правым.

$customer_email = 'rasd@gmail.com';
$customer_detail = Mage::getModel("customer/customer");
$customer_detail->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer_detail->loadByEmail($customer_email);

$storeIds = Mage::app()->getWebsite(Mage::app()->getWebsite()->getId())->getStoreIds();
$quote = Mage::getModel('sales/quote')->setSharedStoreIds($storeIds)->loadByCustomer($customer_detail);
if ($quote) {
$collection = $quote->getItemsCollection();
if($customer_email == 'rasd@gmail.com') {
echo "<pre>";
print_r($collection->getData());
}
if ($collection->count() > 0) { echo $customer_email; die('here');
foreach( $collection as $item ) {
echo "<pre>";
print_r($item->getData());
}
}
}

$collection->getData() - it returns the result array but that one seems wrong.
$item->getData() - No result.

1

Решение

Попробуйте этот код ниже кода. Используйте getItems () вместо функции getItemsCollection (). а также проверьте, расширен Mage_Sales_Model_Quote_Item или нет.

$customer_email = 'rasd@gmail.com';
$customer_detail = Mage::getModel("customer/customer");
$customer_detail->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer_detail->loadByEmail($customer_email);

$storeIds = Mage::app()->getWebsite(Mage::app()->getWebsite()->getId())->getStoreIds();
$quote = Mage::getModel('sales/quote')->setSharedStoreIds($storeIds)->loadByCustomer($customer_detail);
if ($quote) {

$productsResult = array();
foreach ($quote->getAllItems() as $item) {

$product = $item->getProduct();
$productsResult[] = array(// Basic product data
'product_id' => $product->getId(),
'sku' => $product->getSku(),
'name' => $product->getName(),
'set' => $product->getAttributeSetId(),
'type' => $product->getTypeId(),
'category_ids' => $product->getCategoryIds(),
'website_ids' => $product->getWebsiteIds()
);
}
return $productsResult;
}
2

Другие решения

<?php
require_once('app/Mage.php');
umask(0);
Mage::app();

$customerId = 1; // your customer ID
$customer = Mage::getModel('customer/customer')->load($customerId);

$quote = Mage::getModel('sales/quote')
->setSharedStoreIds($storeIds)
->loadByCustomer($customer);

if ($quote) {
$collection = $quote->getItemsCollection();
if ($collection->count() > 0) {
foreach( $collection as $item ) {
echo 'ID: '.$item->getProductId().'<br />';
echo 'Name: '.$item->getName().'<br />';
echo 'Sku: '.$item->getSku().'<br />';
echo 'Quantity: '.$item->getQty().'<br />';
echo 'Price: '.$item->getPrice().'<br />';
echo "<br />";

}
}
}

?>
0