2

I am trying to modify the price in mini cart with a custom product attribute

now the price in the minicart come from:

myproject\vendor\magento\module-checkout\view\frontend\web\template\minicart\item\price.html

and look like this

<div class="price-container">
  <span class="price-wrapper" data-bind="html: price"></span>
 </div>

So, somehow the price is binding.

Does anyone know where this price is binding? or in which part of the code the mini cart product attributes are render?

  • what do you want to do using price? – Rakesh Jesadiya Dec 13 '16 at 9:50
  • 1
    First extend checkout module , on debug mode and you will see all files rendering for price. Please post more details what changes you required in price so that community can answer you question. – Jai Dec 13 '16 at 9:53
  • i create a custom attribute for some rent product, and i want to show in minicart that attribute not the price which is 0 – Alin Lupoiu Dec 13 '16 at 10:00
0

You can follow these steps to resolve the minicart price issue-

STEP.1 Create events.xml file at app/code/YourNamespace/YourModule/etc/frontend

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_cart_product_add_after">
        <observer name="custompricemodule" instance="YourNamespace\YourModule\Observer\CustomPrice" />
    </event>
</config>

STEP.2 Create CustomPrice.php file at app/code/YourNamespace/YourModule/Observer

<?php
namespace YourNamespace\YourModule\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;

class CustomPrice implements ObserverInterface
{

public function execute(\Magento\Framework\Event\Observer $observer) 
{

        $item = $observer->getEvent()->getData('quote_item');         
        $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
        $price = 600; //set your price here
        $item->setCustomPrice($price);
        $item->setOriginalCustomPrice($price);
        $item->getProduct()->setIsSuperMode(true);
    }

}

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.