Overriding Quote Item Weight ProgramaticallyProgrammatically Changing Order's WeightRemove taxes from quote item programaticallyGetting an item from quote objectMagento 2 : Updating quote itemRemove item from Quote item - Magento1.9Quote item price changesMagento 1 OR 2 : Set custom product weight in quoteAdding custom attribute to quote itemHow to programmatically add a customizable Option in magento2?Get quote item collection by using quote item id in Magento 2Get Quote Item's Selected Custom Options

It's a yearly task, alright

Variant calling without matched normal sample

The use of "touch" and "touch on" in context

How to generate globally unique ids for different tables of the same database?

How to make healing in an exploration game interesting

How is the Swiss post e-voting system supposed to work, and how was it wrong?

Does splitting a potentially monolithic application into several smaller ones help prevent bugs?

Why does Deadpool say "You're welcome, Canada," after shooting Ryan Reynolds in the end credits?

Good allowance savings plan?

How could a female member of a species produce eggs unto death?

Pinhole Camera with Instant Film

I need to drive a 7/16" nut but am unsure how to use the socket I bought for my screwdriver

Is a lawful good "antagonist" effective?

Be in awe of my brilliance!

What is IP squat space

Making a sword in the stone, in a medieval world without magic

Does the statement `int val = (++i > ++j) ? ++i : ++j;` invoke undefined behavior?

How do I hide Chekhov's Gun?

Where is the 1/8 CR apprentice in Volo's Guide to Monsters?

My story is written in English, but is set in my home country. What language should I use for the dialogue?

Bash replace string at multiple places in a file from command line

Why do Australian milk farmers need to protest supermarkets' milk price?

Can unconscious characters be unwilling?

Sword in the Stone story where the sword was held in place by electromagnets



Overriding Quote Item Weight Programatically


Programmatically Changing Order's WeightRemove taxes from quote item programaticallyGetting an item from quote objectMagento 2 : Updating quote itemRemove item from Quote item - Magento1.9Quote item price changesMagento 1 OR 2 : Set custom product weight in quoteAdding custom attribute to quote itemHow to programmatically add a customizable Option in magento2?Get quote item collection by using quote item id in Magento 2Get Quote Item's Selected Custom Options













1















My goal is to alter the weight of a product based on a chosen custom option. I have the custom option part working, but am unable to alter the weight of the item is such a way that affects the shipping estimates.



The below code partly works, in that it initially sets the correctly updated weight in the quote_item table. However, this gets overwritten, and is always overwritten before shipping is calculated. Is there a better way to do this? Or should I be plugging in later, perhaps? Any thoughts would be greatly appreciated!



<?php

namespace IbexOptionsModelPlugin;

use MagentoQuoteModelQuote;

class Weight

protected $configurationHelper;

public function __construct(
MagentoCatalogHelperProductConfiguration $configurationHelper
)

$this->configurationHelper = $configurationHelper;


public function beforeSetProduct(MagentoQuoteModelQuoteItem $subject, $product)

$logger = MagentoFrameworkAppObjectManager::getInstance()->get('PsrLogLoggerInterface');

$customOptions = $product->getCustomOptions();

if (isset($customOptions['option_ids']))
$optionIds = $customOptions['option_ids'];

foreach (explode(',', $optionIds->getValue()) as $optionId)
$option = $product->getOptionById($optionId);
if (isset($customOptions['option_'.$optionId]))
$itemOption = $subject->getOptionByCode('option_'.$optionId);

$group = $option->groupFactory($option->getType())
->setOption($option)
->setConfigurationItem($subject)
->setConfigurationItemOption($itemOption);

if($group->getOption()->getValueById($itemOption->getValue()))
$optionValue = $group->getOption()->getValueById($itemOption->getValue());
$selectedWeight = $optionValue->getCustomWeight();




$weight = $product->getWeight();
if(isset($selectedWeight))
$newWeight = $weight + $selectedWeight;

if(isset($newWeight))
$product->setWeight($newWeight);

return [$product];











share|improve this question






















  • For better understanding: The code you are using saves the correct calculated weight value into quote_item table and in a later step in the checkout some other process is overwriting the value?

    – HelgeB
    4 hours ago












  • @HelgeB Correct!

    – Tryingest Fool
    4 hours ago











  • Can you identify the step where it happens? That would make it easier

    – HelgeB
    4 hours ago











  • I'm not sure exactly. But looking at the database, I see the entry being created (with the new weight) in the table, and then it gets updated with the initial weight shortly afterwards.

    – Tryingest Fool
    4 hours ago












  • Well I guess you will have to debug that to see where that change comes from. I'll give you a hint in the chat chat.stackexchange.com/rooms/90428/help

    – HelgeB
    4 hours ago















1















My goal is to alter the weight of a product based on a chosen custom option. I have the custom option part working, but am unable to alter the weight of the item is such a way that affects the shipping estimates.



The below code partly works, in that it initially sets the correctly updated weight in the quote_item table. However, this gets overwritten, and is always overwritten before shipping is calculated. Is there a better way to do this? Or should I be plugging in later, perhaps? Any thoughts would be greatly appreciated!



<?php

namespace IbexOptionsModelPlugin;

use MagentoQuoteModelQuote;

class Weight

protected $configurationHelper;

public function __construct(
MagentoCatalogHelperProductConfiguration $configurationHelper
)

$this->configurationHelper = $configurationHelper;


public function beforeSetProduct(MagentoQuoteModelQuoteItem $subject, $product)

$logger = MagentoFrameworkAppObjectManager::getInstance()->get('PsrLogLoggerInterface');

$customOptions = $product->getCustomOptions();

if (isset($customOptions['option_ids']))
$optionIds = $customOptions['option_ids'];

foreach (explode(',', $optionIds->getValue()) as $optionId)
$option = $product->getOptionById($optionId);
if (isset($customOptions['option_'.$optionId]))
$itemOption = $subject->getOptionByCode('option_'.$optionId);

$group = $option->groupFactory($option->getType())
->setOption($option)
->setConfigurationItem($subject)
->setConfigurationItemOption($itemOption);

if($group->getOption()->getValueById($itemOption->getValue()))
$optionValue = $group->getOption()->getValueById($itemOption->getValue());
$selectedWeight = $optionValue->getCustomWeight();




$weight = $product->getWeight();
if(isset($selectedWeight))
$newWeight = $weight + $selectedWeight;

if(isset($newWeight))
$product->setWeight($newWeight);

return [$product];











share|improve this question






















  • For better understanding: The code you are using saves the correct calculated weight value into quote_item table and in a later step in the checkout some other process is overwriting the value?

    – HelgeB
    4 hours ago












  • @HelgeB Correct!

    – Tryingest Fool
    4 hours ago











  • Can you identify the step where it happens? That would make it easier

    – HelgeB
    4 hours ago











  • I'm not sure exactly. But looking at the database, I see the entry being created (with the new weight) in the table, and then it gets updated with the initial weight shortly afterwards.

    – Tryingest Fool
    4 hours ago












  • Well I guess you will have to debug that to see where that change comes from. I'll give you a hint in the chat chat.stackexchange.com/rooms/90428/help

    – HelgeB
    4 hours ago













1












1








1








My goal is to alter the weight of a product based on a chosen custom option. I have the custom option part working, but am unable to alter the weight of the item is such a way that affects the shipping estimates.



The below code partly works, in that it initially sets the correctly updated weight in the quote_item table. However, this gets overwritten, and is always overwritten before shipping is calculated. Is there a better way to do this? Or should I be plugging in later, perhaps? Any thoughts would be greatly appreciated!



<?php

namespace IbexOptionsModelPlugin;

use MagentoQuoteModelQuote;

class Weight

protected $configurationHelper;

public function __construct(
MagentoCatalogHelperProductConfiguration $configurationHelper
)

$this->configurationHelper = $configurationHelper;


public function beforeSetProduct(MagentoQuoteModelQuoteItem $subject, $product)

$logger = MagentoFrameworkAppObjectManager::getInstance()->get('PsrLogLoggerInterface');

$customOptions = $product->getCustomOptions();

if (isset($customOptions['option_ids']))
$optionIds = $customOptions['option_ids'];

foreach (explode(',', $optionIds->getValue()) as $optionId)
$option = $product->getOptionById($optionId);
if (isset($customOptions['option_'.$optionId]))
$itemOption = $subject->getOptionByCode('option_'.$optionId);

$group = $option->groupFactory($option->getType())
->setOption($option)
->setConfigurationItem($subject)
->setConfigurationItemOption($itemOption);

if($group->getOption()->getValueById($itemOption->getValue()))
$optionValue = $group->getOption()->getValueById($itemOption->getValue());
$selectedWeight = $optionValue->getCustomWeight();




$weight = $product->getWeight();
if(isset($selectedWeight))
$newWeight = $weight + $selectedWeight;

if(isset($newWeight))
$product->setWeight($newWeight);

return [$product];











share|improve this question














My goal is to alter the weight of a product based on a chosen custom option. I have the custom option part working, but am unable to alter the weight of the item is such a way that affects the shipping estimates.



The below code partly works, in that it initially sets the correctly updated weight in the quote_item table. However, this gets overwritten, and is always overwritten before shipping is calculated. Is there a better way to do this? Or should I be plugging in later, perhaps? Any thoughts would be greatly appreciated!



<?php

namespace IbexOptionsModelPlugin;

use MagentoQuoteModelQuote;

class Weight

protected $configurationHelper;

public function __construct(
MagentoCatalogHelperProductConfiguration $configurationHelper
)

$this->configurationHelper = $configurationHelper;


public function beforeSetProduct(MagentoQuoteModelQuoteItem $subject, $product)

$logger = MagentoFrameworkAppObjectManager::getInstance()->get('PsrLogLoggerInterface');

$customOptions = $product->getCustomOptions();

if (isset($customOptions['option_ids']))
$optionIds = $customOptions['option_ids'];

foreach (explode(',', $optionIds->getValue()) as $optionId)
$option = $product->getOptionById($optionId);
if (isset($customOptions['option_'.$optionId]))
$itemOption = $subject->getOptionByCode('option_'.$optionId);

$group = $option->groupFactory($option->getType())
->setOption($option)
->setConfigurationItem($subject)
->setConfigurationItemOption($itemOption);

if($group->getOption()->getValueById($itemOption->getValue()))
$optionValue = $group->getOption()->getValueById($itemOption->getValue());
$selectedWeight = $optionValue->getCustomWeight();




$weight = $product->getWeight();
if(isset($selectedWeight))
$newWeight = $weight + $selectedWeight;

if(isset($newWeight))
$product->setWeight($newWeight);

return [$product];








magento2 quote quoteitem






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 4 hours ago









Tryingest FoolTryingest Fool

175117




175117












  • For better understanding: The code you are using saves the correct calculated weight value into quote_item table and in a later step in the checkout some other process is overwriting the value?

    – HelgeB
    4 hours ago












  • @HelgeB Correct!

    – Tryingest Fool
    4 hours ago











  • Can you identify the step where it happens? That would make it easier

    – HelgeB
    4 hours ago











  • I'm not sure exactly. But looking at the database, I see the entry being created (with the new weight) in the table, and then it gets updated with the initial weight shortly afterwards.

    – Tryingest Fool
    4 hours ago












  • Well I guess you will have to debug that to see where that change comes from. I'll give you a hint in the chat chat.stackexchange.com/rooms/90428/help

    – HelgeB
    4 hours ago

















  • For better understanding: The code you are using saves the correct calculated weight value into quote_item table and in a later step in the checkout some other process is overwriting the value?

    – HelgeB
    4 hours ago












  • @HelgeB Correct!

    – Tryingest Fool
    4 hours ago











  • Can you identify the step where it happens? That would make it easier

    – HelgeB
    4 hours ago











  • I'm not sure exactly. But looking at the database, I see the entry being created (with the new weight) in the table, and then it gets updated with the initial weight shortly afterwards.

    – Tryingest Fool
    4 hours ago












  • Well I guess you will have to debug that to see where that change comes from. I'll give you a hint in the chat chat.stackexchange.com/rooms/90428/help

    – HelgeB
    4 hours ago
















For better understanding: The code you are using saves the correct calculated weight value into quote_item table and in a later step in the checkout some other process is overwriting the value?

– HelgeB
4 hours ago






For better understanding: The code you are using saves the correct calculated weight value into quote_item table and in a later step in the checkout some other process is overwriting the value?

– HelgeB
4 hours ago














@HelgeB Correct!

– Tryingest Fool
4 hours ago





@HelgeB Correct!

– Tryingest Fool
4 hours ago













Can you identify the step where it happens? That would make it easier

– HelgeB
4 hours ago





Can you identify the step where it happens? That would make it easier

– HelgeB
4 hours ago













I'm not sure exactly. But looking at the database, I see the entry being created (with the new weight) in the table, and then it gets updated with the initial weight shortly afterwards.

– Tryingest Fool
4 hours ago






I'm not sure exactly. But looking at the database, I see the entry being created (with the new weight) in the table, and then it gets updated with the initial weight shortly afterwards.

– Tryingest Fool
4 hours ago














Well I guess you will have to debug that to see where that change comes from. I'll give you a hint in the chat chat.stackexchange.com/rooms/90428/help

– HelgeB
4 hours ago





Well I guess you will have to debug that to see where that change comes from. I'll give you a hint in the chat chat.stackexchange.com/rooms/90428/help

– HelgeB
4 hours ago










0






active

oldest

votes











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%2f265987%2foverriding-quote-item-weight-programatically%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















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%2f265987%2foverriding-quote-item-weight-programatically%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

Identifying “long and narrow” polygons in with PostGISlength and width of polygonWhy postgis st_overlaps reports Qgis' “avoid intersections” generated polygon as overlapping with others?Adjusting polygons to boundary and filling holesDrawing polygons with fixed area?How to remove spikes in Polygons with PostGISDeleting sliver polygons after difference operation in QGIS?Snapping boundaries in PostGISSplit polygon into parts adding attributes based on underlying polygon in QGISSplitting overlap between polygons and assign to nearest polygon using PostGIS?Expanding polygons and clipping at midpoint?Removing Intersection of Buffers in Same Layers

Masuk log Menu navigasi

อาณาจักร (ชีววิทยา) ดูเพิ่ม อ้างอิง รายการเลือกการนำทาง10.1086/39456810.5962/bhl.title.447410.1126/science.163.3863.150576276010.1007/BF01796092408502"Phylogenetic structure of the prokaryotic domain: the primary kingdoms"10.1073/pnas.74.11.5088432104270744"Towards a natural system of organisms: proposal for the domains Archaea, Bacteria, and Eucarya"1990PNAS...87.4576W10.1073/pnas.87.12.4576541592112744PubMedJump the queueexpand by handPubMedJump the queueexpand by handPubMedJump the queueexpand by hand"A revised six-kingdom system of life"10.1111/j.1469-185X.1998.tb00030.x9809012"Only six kingdoms of life"10.1098/rspb.2004.2705169172415306349"Kingdoms Protozoa and Chromista and the eozoan root of the eukaryotic tree"10.1098/rsbl.2009.0948288006020031978เพิ่มข้อมูล