Manipulate package weight before shipping rates calculationProgrammatically increase package weightFedex Weight CalculationUSPS Maximum Package Weight Not Restricting WeightShipping price in one page checkout - order review return zeroPhp file weight calculationWhy does the Shipping total set the row_weight of the sales quote items to 0 if free shipping is in effect?Shipping Table rates Weight vs Destination RangesCreating Quote Address the right wayIs Possible Magento Allows Change Shipping Cost calculate by Individual Product Weight instead of Package Weight?CollectRates in custom carrier is not called when weight is over zero. Magento2

Should I have shared a document with a former employee?

How do you name this compound using IUPAC system (including steps)?

Is "repository" pronounced /rɪˈpɒzɪt(ə)ri/ or ri-ˈpä-zə-ˌtȯr-ē or /rəˈpäzəˌtôrē/?

How did Jayne know when to shoot?

Somebody hacked my clock

Locked-up DOS computer beeped on keypress. What mechanism caused that?

What is a Kravchuk transform and how is it related to Fourier transforms?

How important are the Author's mood and feelings for writing a story?

Do higher dimensions have axes?

"This used to be my phone number"

Why would word of Princess Leia's capture generate sympathy for the Rebellion in the Senate?

Who or what determines if a curse is valid or not?

Why is carrying a heavy object more taxing on the body than pushing the same object on wheels?

What's the physical meaning of the statement that "photons don't have positions"?

Inscriptio Labyrinthica

Get Chord Name From a Given Set of Notes

Align the contents of a numerical matrix when you have minus signs

How electronics on board of JWST can survive the low operating temperature while it's difficult to survive lunar night?

How was Luke's prosthetic hand in Episode V filmed?

When will the last unambiguous evidence of mankind disappear?

"Je suis petite, moi?", purpose of the "moi"?

Discontinuous Tube visualization

Why should fork() have been designed to return a file descriptor?

When we are talking about black hole evaporation - what exactly happens?



Manipulate package weight before shipping rates calculation


Programmatically increase package weightFedex Weight CalculationUSPS Maximum Package Weight Not Restricting WeightShipping price in one page checkout - order review return zeroPhp file weight calculationWhy does the Shipping total set the row_weight of the sales quote items to 0 if free shipping is in effect?Shipping Table rates Weight vs Destination RangesCreating Quote Address the right wayIs Possible Magento Allows Change Shipping Cost calculate by Individual Product Weight instead of Package Weight?CollectRates in custom carrier is not called when weight is over zero. Magento2






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








0















I need to add some logic to weight package calculation before shipping rates are calculated. So I created a custom module with an observer on sales_quote_address_collect_totals_after event.



The observer looks like this



use MagentoFrameworkEventObserverInterface;

class AfterCollectTotals implements ObserverInterface

public function execute(MagentoFrameworkEventObserver $observer)


foreach ($items as $item)

// My custom logic here to get the correct weight in $weight


$observer->getQuote()->getShippingAddress()->setWeight($weight);




Weight appears to be set correctly, but when the Shipping Rates are calculated this value is ignored.
In the carrier model, $request->getPackageWeight() returns the package weight before my manipulation.



Where am I wrong?



Thank you










share|improve this question






















  • Have you tried sales_quote_address_collect_totals_before instead ..._after?

    – sv3n
    May 18 '18 at 10:15











  • Yes, but this event is dispatched too late as well

    – Daniele Rovatti
    May 18 '18 at 11:13

















0















I need to add some logic to weight package calculation before shipping rates are calculated. So I created a custom module with an observer on sales_quote_address_collect_totals_after event.



The observer looks like this



use MagentoFrameworkEventObserverInterface;

class AfterCollectTotals implements ObserverInterface

public function execute(MagentoFrameworkEventObserver $observer)


foreach ($items as $item)

// My custom logic here to get the correct weight in $weight


$observer->getQuote()->getShippingAddress()->setWeight($weight);




Weight appears to be set correctly, but when the Shipping Rates are calculated this value is ignored.
In the carrier model, $request->getPackageWeight() returns the package weight before my manipulation.



Where am I wrong?



Thank you










share|improve this question






















  • Have you tried sales_quote_address_collect_totals_before instead ..._after?

    – sv3n
    May 18 '18 at 10:15











  • Yes, but this event is dispatched too late as well

    – Daniele Rovatti
    May 18 '18 at 11:13













0












0








0








I need to add some logic to weight package calculation before shipping rates are calculated. So I created a custom module with an observer on sales_quote_address_collect_totals_after event.



The observer looks like this



use MagentoFrameworkEventObserverInterface;

class AfterCollectTotals implements ObserverInterface

public function execute(MagentoFrameworkEventObserver $observer)


foreach ($items as $item)

// My custom logic here to get the correct weight in $weight


$observer->getQuote()->getShippingAddress()->setWeight($weight);




Weight appears to be set correctly, but when the Shipping Rates are calculated this value is ignored.
In the carrier model, $request->getPackageWeight() returns the package weight before my manipulation.



Where am I wrong?



Thank you










share|improve this question














I need to add some logic to weight package calculation before shipping rates are calculated. So I created a custom module with an observer on sales_quote_address_collect_totals_after event.



The observer looks like this



use MagentoFrameworkEventObserverInterface;

class AfterCollectTotals implements ObserverInterface

public function execute(MagentoFrameworkEventObserver $observer)


foreach ($items as $item)

// My custom logic here to get the correct weight in $weight


$observer->getQuote()->getShippingAddress()->setWeight($weight);




Weight appears to be set correctly, but when the Shipping Rates are calculated this value is ignored.
In the carrier model, $request->getPackageWeight() returns the package weight before my manipulation.



Where am I wrong?



Thank you







shipping magento2.2.2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 18 '18 at 8:21









Daniele RovattiDaniele Rovatti

11911 bronze badges




11911 bronze badges












  • Have you tried sales_quote_address_collect_totals_before instead ..._after?

    – sv3n
    May 18 '18 at 10:15











  • Yes, but this event is dispatched too late as well

    – Daniele Rovatti
    May 18 '18 at 11:13

















  • Have you tried sales_quote_address_collect_totals_before instead ..._after?

    – sv3n
    May 18 '18 at 10:15











  • Yes, but this event is dispatched too late as well

    – Daniele Rovatti
    May 18 '18 at 11:13
















Have you tried sales_quote_address_collect_totals_before instead ..._after?

– sv3n
May 18 '18 at 10:15





Have you tried sales_quote_address_collect_totals_before instead ..._after?

– sv3n
May 18 '18 at 10:15













Yes, but this event is dispatched too late as well

– Daniele Rovatti
May 18 '18 at 11:13





Yes, but this event is dispatched too late as well

– Daniele Rovatti
May 18 '18 at 11:13










2 Answers
2






active

oldest

votes


















0














I've find the solution.



I didn't have to use the observer but the right way is to override




class Shipping in MagentoQuoteModelQuoteAddressTotal




I added my custom logic to public function collect and my custom weight is used to calculate the shipping rates






share|improve this answer























  • The reason is that the event sales_quote_address_collect_totals_after is dispatched after that the shipping methods collect quote totals to calculate rates

    – Daniele Rovatti
    May 18 '18 at 10:13


















0














Same problem.
Im setting new weight on checkout_cart_product_add_after Event.
Weight is set, but the shipping costs are wrong.
How to recalculate the shipping costs?
Has anyone some code snippes please?






share|improve this answer

























    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%2f226544%2fmanipulate-package-weight-before-shipping-rates-calculation%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I've find the solution.



    I didn't have to use the observer but the right way is to override




    class Shipping in MagentoQuoteModelQuoteAddressTotal




    I added my custom logic to public function collect and my custom weight is used to calculate the shipping rates






    share|improve this answer























    • The reason is that the event sales_quote_address_collect_totals_after is dispatched after that the shipping methods collect quote totals to calculate rates

      – Daniele Rovatti
      May 18 '18 at 10:13















    0














    I've find the solution.



    I didn't have to use the observer but the right way is to override




    class Shipping in MagentoQuoteModelQuoteAddressTotal




    I added my custom logic to public function collect and my custom weight is used to calculate the shipping rates






    share|improve this answer























    • The reason is that the event sales_quote_address_collect_totals_after is dispatched after that the shipping methods collect quote totals to calculate rates

      – Daniele Rovatti
      May 18 '18 at 10:13













    0












    0








    0







    I've find the solution.



    I didn't have to use the observer but the right way is to override




    class Shipping in MagentoQuoteModelQuoteAddressTotal




    I added my custom logic to public function collect and my custom weight is used to calculate the shipping rates






    share|improve this answer













    I've find the solution.



    I didn't have to use the observer but the right way is to override




    class Shipping in MagentoQuoteModelQuoteAddressTotal




    I added my custom logic to public function collect and my custom weight is used to calculate the shipping rates







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered May 18 '18 at 10:09









    Daniele RovattiDaniele Rovatti

    11911 bronze badges




    11911 bronze badges












    • The reason is that the event sales_quote_address_collect_totals_after is dispatched after that the shipping methods collect quote totals to calculate rates

      – Daniele Rovatti
      May 18 '18 at 10:13

















    • The reason is that the event sales_quote_address_collect_totals_after is dispatched after that the shipping methods collect quote totals to calculate rates

      – Daniele Rovatti
      May 18 '18 at 10:13
















    The reason is that the event sales_quote_address_collect_totals_after is dispatched after that the shipping methods collect quote totals to calculate rates

    – Daniele Rovatti
    May 18 '18 at 10:13





    The reason is that the event sales_quote_address_collect_totals_after is dispatched after that the shipping methods collect quote totals to calculate rates

    – Daniele Rovatti
    May 18 '18 at 10:13













    0














    Same problem.
    Im setting new weight on checkout_cart_product_add_after Event.
    Weight is set, but the shipping costs are wrong.
    How to recalculate the shipping costs?
    Has anyone some code snippes please?






    share|improve this answer



























      0














      Same problem.
      Im setting new weight on checkout_cart_product_add_after Event.
      Weight is set, but the shipping costs are wrong.
      How to recalculate the shipping costs?
      Has anyone some code snippes please?






      share|improve this answer

























        0












        0








        0







        Same problem.
        Im setting new weight on checkout_cart_product_add_after Event.
        Weight is set, but the shipping costs are wrong.
        How to recalculate the shipping costs?
        Has anyone some code snippes please?






        share|improve this answer













        Same problem.
        Im setting new weight on checkout_cart_product_add_after Event.
        Weight is set, but the shipping costs are wrong.
        How to recalculate the shipping costs?
        Has anyone some code snippes please?







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 11 at 12:38









        MarcelMarcel

        365 bronze badges




        365 bronze badges



























            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%2f226544%2fmanipulate-package-weight-before-shipping-rates-calculation%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

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form