-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store Delivery not working in M2 2.3.4 #28
Comments
Hi there, The fix in Magento Core iMi-digital/magento2@ea70c0b Part of this issue magento/magento2#26682 Regards, |
Hi, VENDOR_NAME/MODULE_NAME/CoreBugFix/Quote/ShippingMethodManagement.php <?php
/**
* @author Matthias Richter, PCS IT-Trading GmbH, Vienna, Austria
* @see https://github.com/magento/magento2/issues/26682
* @see https://github.com/Smile-SA/magento2-module-store-delivery/issues/28
*
* Magento Core Bugfix
*/
namespace VENDOR_NAME\MODULE_NAME\CoreBugFix\Quote;
use Magento\Quote\Model\Quote;
use Magento\Framework\App\ObjectManager;
use Magento\Quote\Api\Data\EstimateAddressInterface;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Quote\Api\Data\AddressInterface;
use Magento\Framework\Reflection\DataObjectProcessor;
class ShippingMethodManagement extends \Magento\Quote\Model\ShippingMethodManagement {
/**
* @var \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor
*/
private $dataProcessor;
/**
* @inheritdoc
*/
public function estimateByExtendedAddress($cartId, AddressInterface $address)
{
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->quoteRepository->getActive($cartId);
// no methods applicable for empty carts or carts with virtual products
if ($quote->isVirtual() || 0 == $quote->getItemsCount()) {
return [];
}
return $this->getShippingMethods($quote, $address);
}
/*
* @inheritDoc
* Get list of available shipping methods
*
* @param \Magento\Quote\Model\Quote $quote
* @param \Magento\Framework\Api\ExtensibleDataInterface $address
* @return \Magento\Quote\Api\Data\ShippingMethodInterface[]
*/
private function getShippingMethods(Quote $quote, $address)
{
$output = [];
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->addData($this->extractAddressData($address));
// Bugfix!!!
$shippingAddress->setExtensionAttributes( $address->getExtensionAttributes() );
$shippingAddress->setCollectShippingRates(true);
$this->totalsCollector->collectAddressTotals($quote, $shippingAddress);
$quoteCustomerGroupId = $quote->getCustomerGroupId();
$customerGroupId = $this->getCustomerSession()->getCustomerGroupId();
$isCustomerGroupChanged = $quoteCustomerGroupId !== $customerGroupId;
if ($isCustomerGroupChanged) {
$quote->setCustomerGroupId($customerGroupId);
}
$shippingRates = $shippingAddress->getGroupedAllShippingRates();
foreach ($shippingRates as $carrierRates) {
foreach ($carrierRates as $rate) {
$output[] = $this->converter->modelToDataObject($rate, $quote->getQuoteCurrencyCode());
}
}
if ($isCustomerGroupChanged) {
$quote->setCustomerGroupId($quoteCustomerGroupId);
}
return $output;
}
/**
* @inheritDoc
* Get transform address interface into Array
*
* @param \Magento\Framework\Api\ExtensibleDataInterface $address
* @return array
*/
private function extractAddressData($address)
{
$className = \Magento\Customer\Api\Data\AddressInterface::class;
if ($address instanceof \Magento\Quote\Api\Data\AddressInterface) {
$className = \Magento\Quote\Api\Data\AddressInterface::class;
} elseif ($address instanceof EstimateAddressInterface) {
$className = EstimateAddressInterface::class;
}
return $this->getDataObjectProcessor()->buildOutputDataArray(
$address,
$className
);
}
/**
* @inheritDoc
* Gets the data object processor
*
* @return \Magento\Framework\Reflection\DataObjectProcessor
* @deprecated 101.0.0
*/
private function getDataObjectProcessor()
{
if ($this->dataProcessor === null) {
$this->dataProcessor = ObjectManager::getInstance()
->get(DataObjectProcessor::class);
}
return $this->dataProcessor;
}
/**
* To avoid copy of constructor, CustomerSession will be injected in the "dirty way". Constructor does it in the same way.
* @author Matthias Richter, PCS IT-Trading GmbH, Vienna, Austria
* @return CustomerSession
*/
private function getCustomerSession() {
return ObjectManager::getInstance()->get(CustomerSession::class);
}
} Register in etc/di.xml (Add following lines) <preference for="Magento\Quote\Api\ShippingMethodManagementInterface" type="VENDOR_NAME\MODULE_NAME\CoreBugFix\Quote\ShippingMethodManagement" />
<preference for="Magento\Quote\Api\ShipmentEstimationInterface" type="VENDOR_NAME\MODULE_NAME\CoreBugFix\Quote\ShippingMethodManagement" />
<preference for="Magento\Quote\Model\ShippingMethodManagementInterface" type="VENDOR_NAME\MODULE_NAME\CoreBugFix\Quote\ShippingMethodManagement" /> Kind regards |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Store Delivery not working in Magento 2.3.4 due to this Magento issue magento/magento2#26682
We can't load the shpping method price in checkout.
The text was updated successfully, but these errors were encountered: