Magento 2 checkout_cart_product_add_after Observer setWeight not working Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Set custom price of product when adding to cart code not workingMagento2 adminhtml_catalog_product_grid_prepare_massaction event is not observedMagento 2 catalog_product_get_final_price event not working for configurable productMagento 2 - Category Save Event is not called when save category via rest apiMagento 2 Enterprise edition, get all custom attributes of product in the observerSet Name of quote_itemMagento-2 : How to set product custom price after add to cartMagento 2 catalog_product_get_final_price event not workingAdd event after user add the product to cart to update quantityMagento 2 controller_action_predispatch observer not working as expected

What is Wonderstone and are there any references to it pre-1982?

Can a USB port passively 'listen only'?

How to align text above triangle figure

How discoverable are IPv6 addresses and AAAA names by potential attackers?

Why am I getting the error "non-boolean type specified in a context where a condition is expected" for this request?

What's the purpose of writing one's academic biography in the third person?

Can a non-EU citizen traveling with me come with me through the EU passport line?

Dating a Former Employee

Why light coming from distant stars is not discrete?

Can an alien society believe that their star system is the universe?

Identifying polygons that intersect with another layer using QGIS?

The logistics of corpse disposal

Can I cast Passwall to drop an enemy into a 20-foot pit?

How do I keep my slimes from escaping their pens?

Why did the rest of the Eastern Bloc not invade Yugoslavia?

Output the ŋarâþ crîþ alphabet song without using (m)any letters

ListPlot join points by nearest neighbor rather than order

When a candle burns, why does the top of wick glow if bottom of flame is hottest?

2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?

Check which numbers satisfy the condition [A*B*C = A! + B! + C!]

How widely used is the term Treppenwitz? Is it something that most Germans know?

Why do people hide their license plates in the EU?

Why was the term "discrete" used in discrete logarithm?

Generate an RGB colour grid



Magento 2 checkout_cart_product_add_after Observer setWeight not working



Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Set custom price of product when adding to cart code not workingMagento2 adminhtml_catalog_product_grid_prepare_massaction event is not observedMagento 2 catalog_product_get_final_price event not working for configurable productMagento 2 - Category Save Event is not called when save category via rest apiMagento 2 Enterprise edition, get all custom attributes of product in the observerSet Name of quote_itemMagento-2 : How to set product custom price after add to cartMagento 2 catalog_product_get_final_price event not workingAdd event after user add the product to cart to update quantityMagento 2 controller_action_predispatch observer not working as expected



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















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



And even now i have tested with magento 2.1 as well. Not working at all



In events.xml and I am creating observer like below



<event name="checkout_cart_product_add_after">
<observer name="checkout_cart_product_add_after_customprice" instance="TestSliderObserverCustomprice" />
</event>


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



$item = $observer->getQuoteItem();
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$item->setCustomPrice(10);
$item->setOriginalCustomPrice(10);
$item->setWeight(10);
$item->getProduct()->setIsSuperMode(true);









share|improve this question
















bumped to the homepage by Community 20 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















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

    – Himmat Paliwal
    Nov 2 '18 at 6:35


















2















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



And even now i have tested with magento 2.1 as well. Not working at all



In events.xml and I am creating observer like below



<event name="checkout_cart_product_add_after">
<observer name="checkout_cart_product_add_after_customprice" instance="TestSliderObserverCustomprice" />
</event>


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



$item = $observer->getQuoteItem();
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$item->setCustomPrice(10);
$item->setOriginalCustomPrice(10);
$item->setWeight(10);
$item->getProduct()->setIsSuperMode(true);









share|improve this question
















bumped to the homepage by Community 20 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















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

    – Himmat Paliwal
    Nov 2 '18 at 6:35














2












2








2








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



And even now i have tested with magento 2.1 as well. Not working at all



In events.xml and I am creating observer like below



<event name="checkout_cart_product_add_after">
<observer name="checkout_cart_product_add_after_customprice" instance="TestSliderObserverCustomprice" />
</event>


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



$item = $observer->getQuoteItem();
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$item->setCustomPrice(10);
$item->setOriginalCustomPrice(10);
$item->setWeight(10);
$item->getProduct()->setIsSuperMode(true);









share|improve this question
















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



And even now i have tested with magento 2.1 as well. Not working at all



In events.xml and I am creating observer like below



<event name="checkout_cart_product_add_after">
<observer name="checkout_cart_product_add_after_customprice" instance="TestSliderObserverCustomprice" />
</event>


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



$item = $observer->getQuoteItem();
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$item->setCustomPrice(10);
$item->setOriginalCustomPrice(10);
$item->setWeight(10);
$item->getProduct()->setIsSuperMode(true);






magento2 magento-2.1 magento-2.0






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '16 at 12:33







Dinesh Saini

















asked Nov 14 '16 at 13:45









Dinesh SainiDinesh Saini

400217




400217





bumped to the homepage by Community 20 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 20 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














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

    – Himmat Paliwal
    Nov 2 '18 at 6:35


















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

    – Himmat Paliwal
    Nov 2 '18 at 6:35

















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

– Himmat Paliwal
Nov 2 '18 at 6:35






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

– Himmat Paliwal
Nov 2 '18 at 6:35











1 Answer
1






active

oldest

votes


















0














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



->setWeight($this->getProduct()->getWeight()) 


coming inside setProduct function in the below file



/vendor/magento/module-quote/Model/Quote/Item.php


And its working for me.






share|improve this answer























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

    – Arjen Miedema
    Feb 27 '18 at 6:24











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f145662%2fmagento-2-checkout-cart-product-add-after-observer-setweight-not-working%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














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



->setWeight($this->getProduct()->getWeight()) 


coming inside setProduct function in the below file



/vendor/magento/module-quote/Model/Quote/Item.php


And its working for me.






share|improve this answer























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

    – Arjen Miedema
    Feb 27 '18 at 6:24















0














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



->setWeight($this->getProduct()->getWeight()) 


coming inside setProduct function in the below file



/vendor/magento/module-quote/Model/Quote/Item.php


And its working for me.






share|improve this answer























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

    – Arjen Miedema
    Feb 27 '18 at 6:24













0












0








0







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



->setWeight($this->getProduct()->getWeight()) 


coming inside setProduct function in the below file



/vendor/magento/module-quote/Model/Quote/Item.php


And its working for me.






share|improve this answer













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



->setWeight($this->getProduct()->getWeight()) 


coming inside setProduct function in the below file



/vendor/magento/module-quote/Model/Quote/Item.php


And its working for me.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 28 '16 at 7:42









Dinesh SainiDinesh Saini

400217




400217












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

    – Arjen Miedema
    Feb 27 '18 at 6:24

















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

    – Arjen Miedema
    Feb 27 '18 at 6:24
















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.

– Arjen Miedema
Feb 27 '18 at 6:24





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.

– Arjen Miedema
Feb 27 '18 at 6:24

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f145662%2fmagento-2-checkout-cart-product-add-after-observer-setweight-not-working%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

Magento 2 disable Secret Key on URL's from terminal The Next CEO of Stack OverflowMagento 2 Shortcut/GUI tool to perform commandline tasks for windowsIn menu add configuration linkMagento oAuth : Generating access token and access secretMagento 2 security key issue in Third-Party API redirect URIPublic actions in admin controllersHow to Disable Cache in Custom WidgetURL Key not changing in Magento 2Product URL Key gets deleted when importing custom options - Magento 2Problem with reindex terminalMagento 2 - bin/magento Commands not working in Cpanel Terminal

Aasi (pallopeli) Navigointivalikko