Hot answers tagged

70

I think you messed up some closing / opening tags and amount of them this code works: <referenceBlock name="checkout.cart.shipping"> <arguments> <argument name="jsLayout" xsi:type="array"> <item name="components" xsi:type="array"> <item name="block-summary" xsi:type="array"> ...


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


41

This is my first answer on this site. I've been struggling trying to make this work for the past two days and I was finally able to make it work, so I though it would be nice to share it. First of all you need to create a module: registration.php etc/module.xml view/frontend/layout/default.xml view/frontend/templates/minicart_open.phtml view/frontend/web/...


35

My suggestion would be to put an observer on the sales_quote_collect_totals_before event which is fired in the Mage_Sales_Model_Quote::collectTotals method before it starts the total collection process. Then from inside this observer method, iterate the quote items and change the tax class on the (already loaded) product object you can retrieve from the ...


35

When I'm interviewing candidates, and in particular junior candidates, I first assess whether they're going to be good developers. Nevermind Magento. So you would hear a lot of generic, non-Magento, questions from me up front. Here are just a few: Explain the difference between a map, a hash, an array, a collection, and a list. Explain what you think "...


32

Mage::helper('checkout/cart')->getItemsCount() -- return shopping cart items count means how many sku add to shopping cart. Mage::helper('checkout/cart')->getSummaryCount() -- return shopping cart items summary (suppose you add sku1 6 qty and sku2 3 qty = total 9 qty return)


31

I'll answer the question in two parts: I. Where should you change the checkout URL? The destination in link.phtml is $block->getCheckoutUrl(). You should not change the template to change functionality, but change the block Magento\Checkout\Block\Onepage\Link instead. To do so create a plugin for it with a method afterGetCheckoutUrl() to change the ...


29

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 }


28

There are many things wrong here and I feel compelled to do a code review with you. See the end for the correct approach. Code review: This line is loading a product with an undefined $sku var: $product = Mage::getModel('catalog/product')->getCollection() ->addAttributeToFilter('sku', $sku) ->addAttributeToSelect('*') ->...


26

The use of Magento\Checkout\Model\Cart is deprecated. You should use the session to get the quote and your cart items. use Magento\Checkout\Model\Session; public function __construct( ... Session $session ... ) { ... $this->_session = $session; ... } public function yourFunction() { $items = ...


24

My guess is that the Magento team is planning to implement service contracts for this class. However as of 2.1 if you check the app/code/Magento/Checkout/Api folder there's no class (yet) that implements such service contract. I assume it'll happen at some point and the Magento team flagged that model to be deprecated in the future. However as I said and ...


21

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 ...


20

The events catalog_product_type_prepare_full_options and catalog_product_type_prepare_lite_options are your friends <?xml version="1.0"?> <config> <modules> <Fooman_Example> <version>0.1.0</version> </Fooman_Example> </modules> <global> <models> ...


19

@Tim gave a talk about this issue on the weekend: https://docs.google.com/presentation/d/1efPznQSVTrT1HAD1xQvCPC-Tgvr8jYok4X7ZEJhm9jE/edit What you want is Method 2: Add Following Event in Config.xml <sales_quote_collect_totals_before> <observers> <hackathon_presentation> <type>singleton</type> <class>modulename/observer&...


18

partial answer 1. Order in Backend does not fully affect rendering The totals are rendered by an "area". The grand total is in the area "footer". See template\checkout\cart\totals.phtml. Passing -1 to renderTotals() renders all areas. So you have to remove $this->renderTotals('footer'); and change$this->renderTotals(); to $this->renderTotals(-1); ...


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 ...


18

I've also encountered this issue and I've found out that in vendor/magento/module-checkout/view/frontend/templates/cart/form.phtml ~line 27, Magento Team seems missed to put a dot for the 'action' classname. It's a small mistake that creates a big problem. Hopefully this will be fixed in 2.2.7 So from action.clear It should be .action.clear *Note: ...


17

If you're new to Magento, this answer likely will not make sense. So either get an experienced Magento developer on this or start brushing up. With that, here's what you can try. Prerequisites Ensure that you have defined terms in Magento under Sales > Terms and conditions Ensure that you have terms enabled in System Configuration > Sales > ...


17

You have to just keep below line in your minicart.phtml file to get updated subtotal , This Below line is workig for all cases if cache is enable its working fine, <span data-bind="html: getCartParam('subtotal')"></span> For getting value of grandtotal,shipping rate, You can get GrandTotal, subtotal and shipping rate for current quote ...


17

The commit that deprecated the cart model is c4e9a77403655646a18d4277de96429c86bd34fa with the message MAGETWO-51558: Mark Checkout Cart model as deprecated This doesn't tell much, especially since this is the only commit that references the internal ticket number "MAGETWO-51558" Since \Magento\Checkout\Api still does not contain any new service ...


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

This will do the trick. From your question, I assume that the customer has already selected their desired shipping method. <?php $quote = Mage::getModel("checkout/session")->getQuote(); $amount = $quote->getShippingAddress()->getShippingAmount(); In fact, there are a number of methods available to you. Such as: <?php $address = $quote-&...


16

If you want to leave taxes enabled and with a value but just remove them from display remove the item with the name tax at the appropriate place. For example to remove tax from the checkout cart sidebar add this to your themes (or module) app/design/frontend/<vendor>/<theme>/Magento_Checkout/layout/checkout_cart_index.xml: <referenceBlock ...


15

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 ...


15

I finally found the answer to this. The sticky behavior of the cart summary is due to the code in the file magento_root/vendor/magento/theme-frontend-blank/Magento_Theme/web/js/theme.js. $('.cart-summary').mage('sticky', { container: '#maincontent' }); To remove this functionality, I copied the file theme.js to my theme magento_root/app/design/frontend/...


15

If you need to work with DOM elements, rendered by knockout from this template, you can use afterRender binding. <div data-bind="afterRender: function() {alert('yes');}"></div>


15

You can try the below code. require([ 'Magento_Customer/js/customer-data' ], function (customerData) { var sections = ['cart']; customerData.invalidate(sections); customerData.reload(sections, true); });


14

It's not a single call statement, but here is how you can do it: Setup an observer to listen to the checkout_cart_add_product_complete and set a flag on the core/session object: Mage::getSingleton('core/session')->setProductAddedToCartFlag(true); When you are redirected back to the product page, you'll now have a flag set on the session object. You can ...


14

I don't know exactly how you can solve this but I can explain the problem, maybe it helps. I see that the product page is on https but when you click on the add to cart button the form is submitted to http://francesandalbert.com/checkout/cart/add/uenc/aHR0cDovL2ZyYW5jZXNhbmRhbGJlcnQuY29tL3JpbmcuaHRtbD9fX19TSUQ9VQ,,/product/172/. Notice the http. Then ...


14

First edit the cart template /app/design/frontend/{package}/{theme}/template/checkout/cart.phtml and add an id on the form element for easier access. Let's say you add 'id="cart-form"'; Now edit the templates that render the cart items: app/design/frontend/{package}/{theme}/template/checkout/cart/item/default.phtml app/design/frontend/{package}/{theme}/...


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