I am working with Magento 2.0.10, I have created an observer to set the product price and weight posted from the products details page using a custom attribute. In the below example I am trying to set a static price and weight. For the price attribute its working correctly, but I am not able to set the weight. The quote item is giving the actual product weight while calculating shipping. Even if I change the observer event to sales_quote_item_set_product, it is not working at all for changing weight.

And even now I have tested with Magento 2.1 as well, but it isn't working at all

In events.xml and I am creating an observer like below

<event name="checkout_cart_product_add_after">
    <observer name="checkout_cart_product_add_after_customprice" instance="Test\Slider\Observer\Customprice" />

And script that i have used in my observer is working like this

$item = $observer->getQuoteItem();
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
  • It would be saving under field row_weight, not sure why but if you can adjust to use it at required places by using $item->getRowWeight() in your calculations.. Nov 2 '18 at 6:35

You could achieve this using a plugin:




<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <module name="Product_SetWeight"/>


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<type name="Magento\Quote\Model\Quote\Item">
    <plugin name="product_set_weight" type="Product\SetWeight\Plugin\ItemWeight"/>



namespace Product\SetWeight\Plugin;

class ItemWeight
    public function afterSetProduct(\Magento\Quote\Model\Quote\Item $subject, $result)
        $weight = "3";
        return $result;

This solution is of course missing custom logic to determine which products should be changed and how!

Hope I've been able to help people revisiting this thread.


Finally , i have found the solution. May be it's not the best solution , but it works

I have just commented line number 422 with script


coming inside setProduct function in the below file


And its working for me.

  • 1
    You know that changing code in a file that's in vendor will be overwritten as soon as a newer version of that file/module is available and installed. I have to be honest, I don't know the answer right away, but I don't think this will be the solution you're looking for. Feb 27 '18 at 6:24

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.