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

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

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?