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

Masuk log Menu navigasi

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

Старые Смолеговицы Содержание История | География | Демография | Достопримечательности | Примечания | НавигацияHGЯOLHGЯOL41 206 832 01641 606 406 141Административно-территориальное деление Ленинградской области«Переписная оброчная книга Водской пятины 1500 года», С. 793«Карта Ингерманландии: Ивангорода, Яма, Копорья, Нотеборга», по материалам 1676 г.«Генеральная карта провинции Ингерманландии» Э. Белинга и А. Андерсина, 1704 г., составлена по материалам 1678 г.«Географический чертёж над Ижорскою землей со своими городами» Адриана Шонбека 1705 г.Новая и достоверная всей Ингерманландии ланткарта. Грав. А. Ростовцев. СПб., 1727 г.Топографическая карта Санкт-Петербургской губернии. 5-и верстка. Шуберт. 1834 г.Описание Санкт-Петербургской губернии по уездам и станамСпецкарта западной части России Ф. Ф. Шуберта. 1844 г.Алфавитный список селений по уездам и станам С.-Петербургской губернииСписки населённых мест Российской Империи, составленные и издаваемые центральным статистическим комитетом министерства внутренних дел. XXXVII. Санкт-Петербургская губерния. По состоянию на 1862 год. СПб. 1864. С. 203Материалы по статистике народного хозяйства в С.-Петербургской губернии. Вып. IX. Частновладельческое хозяйство в Ямбургском уезде. СПб, 1888, С. 146, С. 2, 7, 54Положение о гербе муниципального образования Курское сельское поселениеСправочник истории административно-территориального деления Ленинградской области.Топографическая карта Ленинградской области, квадрат О-35-23-В (Хотыницы), 1930 г.АрхивированоАдминистративно-территориальное деление Ленинградской области. — Л., 1933, С. 27, 198АрхивированоАдминистративно-экономический справочник по Ленинградской области. — Л., 1936, с. 219АрхивированоАдминистративно-территориальное деление Ленинградской области. — Л., 1966, с. 175АрхивированоАдминистративно-территориальное деление Ленинградской области. — Лениздат, 1973, С. 180АрхивированоАдминистративно-территориальное деление Ленинградской области. — Лениздат, 1990, ISBN 5-289-00612-5, С. 38АрхивированоАдминистративно-территориальное деление Ленинградской области. — СПб., 2007, с. 60АрхивированоКоряков Юрий База данных «Этно-языковой состав населённых пунктов России». Ленинградская область.Административно-территориальное деление Ленинградской области. — СПб, 1997, ISBN 5-86153-055-6, С. 41АрхивированоКультовый комплекс Старые Смолеговицы // Электронная энциклопедия ЭрмитажаПроблемы выявления, изучения и сохранения культовых комплексов с каменными крестами: по материалам работ 2016-2017 гг. в Ленинградской области