2

I get informational cards, but I need to show it to the customer, for example, to show a specific product, name, price, and the customer which bought this product. Getting cart info

class Index extends \Magento\Framework\View\Element\Template
  {

     public function __construct(

    \Magento\Backend\Block\Template\Context $context,

    \Magento\Checkout\Model\Cart $cart,

    array $data = []

   )

   {

    $this->cart = $cart;

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

   }

   public function getCartInfo()
   {

    return $this->cart->getQuote()->getItemsCollection();

   }

 }

Can somebody help?

0
-2

Try this

$itemsCollection = $cart->getQuote()->getItemsCollection();

// get array of all items what can be display directly
$itemsVisible = $cart->getQuote()->getAllVisibleItems();

// retrieve quote items array
 $items = $cart->getQuote()->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 customer details */

$customer=$cart->getQuote()->getCustomer();
$Customerid = $customer->getId();
$Customeremail = $customer->getEmail();
$Customer_firstname = $customer->getFirstname();
$Customer_lastname = $customer->getLastname();
11
  • How can i get customer name or id for each cart information ? – Robinio Apr 27 '19 at 11:49
  • I need to get Customer (name or id )with his cart info – Robinio Apr 27 '19 at 11:51
  • In backend, thanks for answer – Robinio Apr 27 '19 at 11:51
  • Check my updated code. I have added getting customer details – Arunprabakaran M Apr 27 '19 at 12:07
  • 1
    $customer=$cart->getQuote()->getCustomer();. You can get customer details only for logged in user, otherwise, you can able to get customer details. It's not a bad answer. Kindly check with logged in user. it works fine – Arunprabakaran M Apr 29 '19 at 7:28

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.