Skip to content

Commit

Permalink
Merge pull request #192 from WGenie/feature/getcarriercode-on-null
Browse files Browse the repository at this point in the history
Fatal error: Uncaught Error: Call to a member function getCarrierCode…
  • Loading branch information
jissereitsma authored Sep 27, 2023
2 parents 3c5123a + baf9e30 commit b63898c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions DataLayer/Event/AddShippingInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public function get(): array

if (!$shippingMethod) {
$quoteId = $this->checkoutSession->getQuote()->getId();
$shippingMethod = $this->shippingMethodManagement->get($quoteId);
$shippingMethod = $shippingMethod->getCarrierCode().'_'.$shippingMethod->getMethodCode();
$shippingMethod = $this->getShippingMethodFromQuote((int)$quoteId);
}

if (!$shippingMethod) {
Expand All @@ -56,4 +55,22 @@ public function get(): array
],
];
}

/**
* Cart2Quote compatibility. When creating a quote there is no shipping info.
* shippingMethodManagement returns null and causes error on function getCarrierCode()
*
* @param int $quoteId
* @return string|null
*/
public function getShippingMethodFromQuote(int $quoteId): ?string
{
$shippingMethod = $this->shippingMethodManagement->get($quoteId);

Check failure on line 68 in DataLayer/Event/AddShippingInfo.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to an undefined method Magento\Quote\Api\ShippingMethodManagementInterface::get().
if(!is_null($shippingMethod)) {

return $shippingMethod->getCarrierCode().'_'.$shippingMethod->getMethodCode();
}

return null;
}
}

0 comments on commit b63898c

Please sign in to comment.