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
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
add a comment |
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
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
add a comment |
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
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
magento2 quote quoteitem
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
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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