1

I want cart items like product ids, product names of particular customer id.

Is there any solution for this?

1

I assume you have a block and a template file, so try with

app/code/MYCOMPANY/EXTENSION/Block/Stackoverflow.php

protected $checkoutSession;    

public function __construct(
    \Magento\Backend\Block\Template\Context $context,
    ...
    \Magento\Checkout\Model\Session $checkoutSession,
    array $data = []
)
{
    $this->checkoutSession = $checkoutSession;

    parent::__construct($context, $data);
}

public function getCheckoutSession()
{
    return $this->_checkoutSession;
}

app/design/MYCOMPANY_THEME/something/here/Stackoverflow.phtml

// Get all items in cart

$quote = $block->getCheckoutSession()->getQuote()->loadByCustomer($customerId);
$items = $quote->getAllItems();

foreach($items 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 />";            
}

// Get total items and total quantity in cart

$totalItems = $quote->getItemsCount();
$totalQuantity = $quote->getItemsQty();

//Get subtotal and grand total price of cart

$subTotal = $quote->getSubtotal();
$grandTotal = $quote->getGrandTotal();

//Get billing and shipping addresses

$billingAddress = $quote->getBillingAddress();
$shippingAddress = $quote->getShippingAddress();
| improve this answer | |
1

Try this:

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
 $quote= $objectManager->create('Magento\Quote\Model\Quote')->loadByCustomer($c‌​ustomerId); 
 $quoteItems=$quote->getAllVisibleItems();
 foreach($quoteItems as $oneItem){
 //$oneItem->getName();
 //$oneItem->getProductId();
 }
| improve this answer | |
  • This is Magento 2 question, not Magento 1. – Toan Nguyen Jun 13 '17 at 8:00
  • @ToanNguyen I have edited my answer. Please have a look. – Prasanta Hatui Jun 13 '17 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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