Magento 2: How can I get Customer during collectRates on custom shipping methodHow to add custom attribute to shipping method in magento2Custom Shipping Method - Please specify a shipping methodHow can i save custom field value in customer_entity table in Magento 2 using observerIs there any method to get cart details inside a plugin feature in Magento 2Migrating Shipping Extension for Magento 1.9 to Magento 2.2Magento 2 custom address attribute not loading in address book in checkout pageOverwrite Constructor to inject custom module helperSplit shipping with backorder - Magento 2Magento 2 Override Magento Checkout Model Cart updateItems functionMagento 2 - At Checkout page, the City Id is displaying in Shipping Address not the City Name

Can a cyclic Amine form an Amide?

Accidentally deleted the "/usr/share" folder

Was the ancestor of SCSI, the SASI protocol, nothing more than a draft?

Survey Confirmation - Emphasize the question or the answer?

Applying a function to a nested list

How does NAND gate work? (Very basic question)

A non-technological, repeating, phenomenon in the sky, holding its position in the sky for hours

Can I use 1000v rectifier diodes instead of 600v rectifier diodes?

CRT Oscilloscope - part of the plot is missing

Does hiding behind 5-ft-wide cover give full cover?

Did we get closer to another plane than we were supposed to, or was the pilot just protecting our delicate sensibilities?

Feels like I am getting dragged into office politics

How could a planet have most of its water in the atmosphere?

Was Unix ever a single-user OS?

How to assert on pagereference where the endpoint of pagereference is predefined

How to creep the reader out with what seems like a normal person?

Stark VS Thanos

Does the Darkness spell dispel the Color Spray and Flaming Sphere spells?

How do I tell my manager that his code review comment is wrong?

Can fracking help reduce CO2?

Has any spacecraft ever had the ability to directly communicate with civilian air traffic control?

Copy line and insert it in a new position with sed or awk

If Melisandre foresaw another character closing blue eyes, why did she follow Stannis?

What does air vanishing on contact sound like?



Magento 2: How can I get Customer during collectRates on custom shipping method


How to add custom attribute to shipping method in magento2Custom Shipping Method - Please specify a shipping methodHow can i save custom field value in customer_entity table in Magento 2 using observerIs there any method to get cart details inside a plugin feature in Magento 2Migrating Shipping Extension for Magento 1.9 to Magento 2.2Magento 2 custom address attribute not loading in address book in checkout pageOverwrite Constructor to inject custom module helperSplit shipping with backorder - Magento 2Magento 2 Override Magento Checkout Model Cart updateItems functionMagento 2 - At Checkout page, the City Id is displaying in Shipping Address not the City Name






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















How can I get the customer and cart during collectRates() function of my custom shipping method.



public function __construct(
MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory,
PsrLogLoggerInterface $logger,
MagentoShippingModelRateResultFactory $rateResultFactory,
MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory,
MagentoCheckoutModelCart $cart,
MagentoCustomerModelSession $customerSession,
array $data = []
)
$this->_cart = $cart;
$this->_rateResultFactory = $rateResultFactory;
$this->_rateMethodFactory = $rateMethodFactory;
$this->_customerSession = $customerSession;

parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);


public function collectRates(RateRequest $request)
{

if (!$this->getConfigFlag('active'))
return false;


if(!$this->_customerSession->isLoggedIn())
return false;


$customer = $this->_customerSession->getCustomer();
$qty = $this->_cart->getItemsQty();
...


Using customer session and checking if isLoggedIn() only works for frontend but returns false when placing order in the admin.



How can I get customer properly and calculate my price per item for both frontend and admin order placement?










share|improve this question




























    0















    How can I get the customer and cart during collectRates() function of my custom shipping method.



    public function __construct(
    MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
    MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory,
    PsrLogLoggerInterface $logger,
    MagentoShippingModelRateResultFactory $rateResultFactory,
    MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory,
    MagentoCheckoutModelCart $cart,
    MagentoCustomerModelSession $customerSession,
    array $data = []
    )
    $this->_cart = $cart;
    $this->_rateResultFactory = $rateResultFactory;
    $this->_rateMethodFactory = $rateMethodFactory;
    $this->_customerSession = $customerSession;

    parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);


    public function collectRates(RateRequest $request)
    {

    if (!$this->getConfigFlag('active'))
    return false;


    if(!$this->_customerSession->isLoggedIn())
    return false;


    $customer = $this->_customerSession->getCustomer();
    $qty = $this->_cart->getItemsQty();
    ...


    Using customer session and checking if isLoggedIn() only works for frontend but returns false when placing order in the admin.



    How can I get customer properly and calculate my price per item for both frontend and admin order placement?










    share|improve this question
























      0












      0








      0








      How can I get the customer and cart during collectRates() function of my custom shipping method.



      public function __construct(
      MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
      MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory,
      PsrLogLoggerInterface $logger,
      MagentoShippingModelRateResultFactory $rateResultFactory,
      MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory,
      MagentoCheckoutModelCart $cart,
      MagentoCustomerModelSession $customerSession,
      array $data = []
      )
      $this->_cart = $cart;
      $this->_rateResultFactory = $rateResultFactory;
      $this->_rateMethodFactory = $rateMethodFactory;
      $this->_customerSession = $customerSession;

      parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);


      public function collectRates(RateRequest $request)
      {

      if (!$this->getConfigFlag('active'))
      return false;


      if(!$this->_customerSession->isLoggedIn())
      return false;


      $customer = $this->_customerSession->getCustomer();
      $qty = $this->_cart->getItemsQty();
      ...


      Using customer session and checking if isLoggedIn() only works for frontend but returns false when placing order in the admin.



      How can I get customer properly and calculate my price per item for both frontend and admin order placement?










      share|improve this question














      How can I get the customer and cart during collectRates() function of my custom shipping method.



      public function __construct(
      MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
      MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory,
      PsrLogLoggerInterface $logger,
      MagentoShippingModelRateResultFactory $rateResultFactory,
      MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory,
      MagentoCheckoutModelCart $cart,
      MagentoCustomerModelSession $customerSession,
      array $data = []
      )
      $this->_cart = $cart;
      $this->_rateResultFactory = $rateResultFactory;
      $this->_rateMethodFactory = $rateMethodFactory;
      $this->_customerSession = $customerSession;

      parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);


      public function collectRates(RateRequest $request)
      {

      if (!$this->getConfigFlag('active'))
      return false;


      if(!$this->_customerSession->isLoggedIn())
      return false;


      $customer = $this->_customerSession->getCustomer();
      $qty = $this->_cart->getItemsQty();
      ...


      Using customer session and checking if isLoggedIn() only works for frontend but returns false when placing order in the admin.



      How can I get customer properly and calculate my price per item for both frontend and admin order placement?







      magento2 shipping-method






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 22 at 19:53









      Cmaclean066Cmaclean066

      153




      153






















          1 Answer
          1






          active

          oldest

          votes


















          1














          If you can detect when your code runs in Admin, you can use
          MagentoBackendModelSessionQuote
          as your [admin_session] and use [admin_session]->getCustomerId(), along with the customer repository (inject interfaces in constructor and let DI pass the correct objects) to fetch the customer object.



          I would suggest to check the contents of the MagentoBackendModelSessionQuote object, as it might contain a pre-loaded customer object already, in which case you can avoid loading it.



          You could use MagentoFrameworkAppState::getAreaCode() to check if within admin






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2fstackoverflow.com%2fquestions%2f55306947%2fmagento-2-how-can-i-get-customer-during-collectrates-on-custom-shipping-method%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            If you can detect when your code runs in Admin, you can use
            MagentoBackendModelSessionQuote
            as your [admin_session] and use [admin_session]->getCustomerId(), along with the customer repository (inject interfaces in constructor and let DI pass the correct objects) to fetch the customer object.



            I would suggest to check the contents of the MagentoBackendModelSessionQuote object, as it might contain a pre-loaded customer object already, in which case you can avoid loading it.



            You could use MagentoFrameworkAppState::getAreaCode() to check if within admin






            share|improve this answer



























              1














              If you can detect when your code runs in Admin, you can use
              MagentoBackendModelSessionQuote
              as your [admin_session] and use [admin_session]->getCustomerId(), along with the customer repository (inject interfaces in constructor and let DI pass the correct objects) to fetch the customer object.



              I would suggest to check the contents of the MagentoBackendModelSessionQuote object, as it might contain a pre-loaded customer object already, in which case you can avoid loading it.



              You could use MagentoFrameworkAppState::getAreaCode() to check if within admin






              share|improve this answer

























                1












                1








                1







                If you can detect when your code runs in Admin, you can use
                MagentoBackendModelSessionQuote
                as your [admin_session] and use [admin_session]->getCustomerId(), along with the customer repository (inject interfaces in constructor and let DI pass the correct objects) to fetch the customer object.



                I would suggest to check the contents of the MagentoBackendModelSessionQuote object, as it might contain a pre-loaded customer object already, in which case you can avoid loading it.



                You could use MagentoFrameworkAppState::getAreaCode() to check if within admin






                share|improve this answer













                If you can detect when your code runs in Admin, you can use
                MagentoBackendModelSessionQuote
                as your [admin_session] and use [admin_session]->getCustomerId(), along with the customer repository (inject interfaces in constructor and let DI pass the correct objects) to fetch the customer object.



                I would suggest to check the contents of the MagentoBackendModelSessionQuote object, as it might contain a pre-loaded customer object already, in which case you can avoid loading it.



                You could use MagentoFrameworkAppState::getAreaCode() to check if within admin







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 25 at 20:55









                Dmitri SologoubenkoDmitri Sologoubenko

                2,67811625




                2,67811625





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • 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%2fstackoverflow.com%2fquestions%2f55306947%2fmagento-2-how-can-i-get-customer-during-collectrates-on-custom-shipping-method%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현