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;
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
add a comment |
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
add a comment |
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
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
magento2 shipping-method
asked Mar 22 at 19:53
Cmaclean066Cmaclean066
153
153
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
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%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
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
add a comment |
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
add a comment |
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
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
answered Mar 25 at 20:55
Dmitri SologoubenkoDmitri Sologoubenko
2,67811625
2,67811625
add a comment |
add a comment |
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.
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%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
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