Hot answers tagged

65

$cart = Mage::getModel('checkout/cart')->getQuote(); foreach ($cart->getAllItems() as $item) { $productName = $item->getProduct()->getName(); $productPrice = $item->getProduct()->getPrice(); } in $cart you got all collection of cart item and if you want to get product id,name you can get from using foreach loop


30

I found another solution. The following code works for me. $quote = Mage::getSingleton('checkout/session')->getQuote(); $cartItems = $quote->getAllVisibleItems(); foreach ($cartItems as $item) { $productId = $item->getProductId(); // Do something more }


30

Set the store first: $store = Mage::getSingleton('core/store')->load(1); $quote = Mage::getModel('sales/quote')->setStore($store)->load($quoteId);


28

you can inject in your class an instance of \Magento\Quote\Model\QuoteFactory. protected $quoteFactory; public function __construct( ... \Magento\Quote\Model\QuoteFactory $quoteFactory, .... ) { .... $this->quoteFactory = $quoteFactory; .... } Then you can use: $quote = $this->quoteFactory->create()->load($quoteId);...


23

There are several methods that work in a different way: $items = Mage::getSingleton('checkout/cart')->getQuote()->getItemsCollection(); Returns a quote item collection with all items associated to the current quote. $items = Mage::getSingleton('checkout/cart')->getItems(); This is a shortcut for the method above, but if there is no quote it ...


22

Don't do this. Your problem is, that the cart is not yet saved, have a look here: https://github.com/LokeyCoding/magento-mirror/blob/magento-1.7/app/code/core/Mage/Checkout/controllers/CartController.php#L201-L206 public function addAction() { // ... $cart->addProduct($product, $params); // <-- you are inside this method if (!empty($...


19

The quote is set into super mode in app/code/core/Mage/Adminhtml/Model/Session/Quote.php: $this->_quote->setIsSuperMode(true); Essentially it is a flag on the quote that this quote has been created by an admin. The effect of this is in the locations you stated that an admin can for example create an order for an item that normally would be out of ...


18

Nice wrap up of the bug above, Fabian! For any further users who will come accross this bug, there is already a patch from Magento for this. As an Enterprise customer, you can request/download PATCH_SUPEE-6190_EE_1.14.2.0_v1.sh to fix this. Update 24.02.2016: This was also addressed in the latest SUPEE-7405 v 1.1 patch. According to Fabian on Twitter (see ...


17

I am not sure about my below solution: May be you need to load Quote item object by item id As you want set price then using setPrice() you cannot set your desire price for that cart item $item = $quote->getItemById($item->getId()); if (!$item) { continue; } $item->setQty((double) $qty); $item->setCustomPrice($price); $item->...


16

It turned out that this is a bug in Mage_Sales_Model_Quote_Item::compare() that was introduced in Magento CE 1.9.2 / EE 1.14.2. The method is used to compare items to decide if they are the same product and can be merged (during login and when adding products to the cart). When comparing all custom options, it should skip the options that are not ...


14

/app/code/core/Mage/Sales/Model/Quote.php is the Quote class for the quote object /app/code/core/Mage/Sales/Model/Quote/Address.php is the Quote Address class for any quote address objects A quote object would normally contain 2 address objects, but can contain more if multiple delivery addresses are present. In regards to the 'collecttotals' method(s):...


14

First you need to inject a \Magento\Quote\Model\QuoteFactory in your class constructor: protected $_quoteFactory; public function __construct( ... \Magento\Quote\Model\QuoteFactory $quoteFactory ) { $this->_quoteFactory = $quoteFactory; parent::__construct(...); } Then in your class you can do: $this->_quoteFactory->create()->...


12

app/code/Vendor/Module/etc/catalog_attributes.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd"> <group name="quote_item"> <attribute name="custom_attribute"/> </group> </config&...


10

it is not that easy, because one quote item can have more than one children (grouped, bundle items). Therefore I suggest something like: $returnItems = array(); foreach($order->getQuote()->getAllVisibleItems() as $item){ if($item->getHasChildren()) { foreach($item->getChildrenItems() as $child) { $returnItems[...


10

Use array_diff. $order = $invoice->getOrder(); $billing = $order->getBillingAddress()->getData(); $shipping = $order->getShippingAddress()->getData(); $diff = array_diff($billing,$shipping); ref: http://us3.php.net/array_diff you may have to strip out some of the data of each array, before the diff. I am sure you can work it out ;)


10

Sure, the quote_id is saved with the order, so you can just: $order->getQuoteId() And the method should work too, maybe you couldn't load the order... To get the order, you can hook in one of the events after the order creation: checkout_onepage_controller_success_action checkout_type_onepage_save_order_after checkout_submit_all_after If you only ...


10

You can also use the cart helper protected $cartHelper; public function __construct( \Magento\Checkout\Helper\Cart $cartHelper ) { $this->cartHelper = $cartHelper; } and then you can do the check if ($this->cartHelper->getItemsCount() === 0) { //add your functionality }


10

private $quoteItemFactory; private $itemResourceModel; public function __construct( ..... \Magento\Quote\Model\Quote\ItemFactory $quoteItemFactory, \Magento\Quote\Model\ResourceModel\Quote\Item $itemResourceModel ...... ) { .... $this->quoteItemFactory = $quoteItemFactory; $this->itemResourceModel = $itemResourceModel ... } and in ...


9

A quote is actually a 'cart' object. A customer can have many quotes. One for each website. the quote object is not created when the customer is created. It is created when the customer adds the first product to the cart. Also a quote is not necessarily assigned to a customer. You can have a quote when browsing the website as guest. In that case the quote ...


9

@user1240207 Please use the below code. It will may help you. Mage::getSingleton('checkout/session')->setQuoteId($_quote->getId()); Code convert an order to quote please used below: $quote = Mage::getModel('sales/quote')->load($order->getQuoteId()); if ($quote->getId()) { $quote->setIsActive(1) //->...


9

It appears fieldsets are no longer an option for moving custom data fields around. Not clear if this is intentional, or a side-effect of other changes. I just ran into the same problem with payments. I traced that back to \Magento\Quote\Model\Quote\Payment\ToOrderPayment::convert(): public function convert(Payment $object, $data = []) { $paymentData = $...


9

A quote is cart object, this quote is created when the customer adds the first product to the cart and its not created when the customer is created. A customer can have many quotes. One for each website. a quote is not necessarily assigned to a customer, the proof; you can have a quote as guest. Quote is an order that hasn't been placed yet. It contains ...


8

In order to add column to sales_flat_quote_item you will have to write an upgrade script for that follow below steps. Create a module or use your existing custom module. Modify your config.xml to add a setup resource with class Mage_Sales_Model_Resource_Setup: <global> <resources> <your_module_setup> <setup> ...


8

If you go to Magento Admin -> Reports -> Shopping Cart -> Abandoned Carts You will see that Magento let's you pick the date, customer email etc. filters on the quote report table to get the abandoned carts. Magento leaves it up to you to decide what you want to call an abandoned cart. The only thing you need to check to ensure that an order hasn'...


8

I ended up using plugin di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Checkout\Model\Cart"> <plugin name="interceptUpdateProductToCart" type="Mycompany\Inventory\Plugin\...


8

You can display cart items sub-total to header minicart link. Add below code to minicart.phtml to display cart items total <span data-bind="html: getCartParam('subtotal')"></span> php bin/magento cache:clean


7

Even though there is already an accepted answer, I'd like to share this solution I saw (similar) once in a 3rd party module: function serializeAddress(Mage_Sales_Model_Quote_Address $address) { return serialize( array( 'firstname' => $address->getFirstname(), 'lastname' => $address->...


7

Okay, so here's my attempt following ProxiBlue's suggestion: $excludeKeys = array('entity_id', 'customer_address_id', 'quote_address_id', 'region_id', 'customer_id', 'address_type'); $oBillingAddress = $order->getBillingAddress()->getData(); $oShippingAddress = $order->getShippingAddress()->getData(); $oBillingAddressFiltered = array_diff_key($...


7

I was hunting around for this too, and it looks like the quote/address class has a routine that does what we want, called importCustomerAddress: $quoteShippingAddress->importCustomerAddress($customer->getDefaultShippingAddress()); $quoteShippingAddress->save();


7

Have a look at the merge() method in Mage_Sales_Model_Quote. I've never used it, but it should be something such as: $quoteA = Mage::getModel('sales/quote')->load('5'); $quoteB = Mage::getModel('sales/quote')->load('77'); $quoteB->merge($quoteA); // Also? $quoteB->collectTotals()->save(); Zend_Debug::dump($quoteB->getAllItems()); // ...


Only top voted, non community-wiki answers of a minimum length are eligible