-
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
Firstname and Lastname not filled when Guest in the shipping Address When DeliveryInStore Used #19
Comments
Have you always the bug ? Can you tell me more ? |
Hi @Fdec, Indeed, it is still an issue on our environment we created a plugin to for our payment method to fill the gap of these missing field. the plugin look like this : <?php
/**
* Kathmandu StoreDelivery.
*
* @category Mage
*
* @author Sebastien MATHIEU <[email protected]>
* @copyright 2019 Kathmandu Ltd (https://www.kathmandu.co.nz)
*/
namespace Kathmandu\StoreDelivery\Plugin\Checkout\Api;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Model\QuoteIdMaskFactory;
/**
* Class SavePaymentInformationPlugin.
*
* @magentoAppArea adminhtml
* @codingStandardsIgnoreFile
*/
class SaveGuestPaymentInformationPlugin
{
/**
* @var CartRepositoryInterface
*/
private $quoteRepository;
/**
* @var QuoteIdMaskFactory
*/
private $quoteIdMaskFactory;
/**
* @param CartRepositoryInterface $quoteRepository Retailer Repository
* @param QuoteIdMaskFactory $quoteIdMaskFactory Customer session
*/
public function __construct(
CartRepositoryInterface $quoteRepository,
QuoteIdMaskFactory $quoteIdMaskFactory
) {
$this->quoteRepository = $quoteRepository;
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
}
/**
* @param \Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject
* @param $cartId
* @param $email
* @param $paymentMethod
* @param $billingAddress
*
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
// @codingStandardsIgnoreStart
public function beforeSavePaymentInformation(//AndPlaceOrder
\Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject,
$cartId,
$email,
$paymentMethod,
$billingAddress
) {
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->quoteRepository->get($quoteIdMask->getQuoteId());
$shippingAddress = $quote->getShippingAddress();
$this->modifyShippingAddress($shippingAddress, $billingAddress);
return;
}
/**
* @param \Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject
* @param $cartId
* @param $email
* @param $paymentMethod
* @param $billingAddress
*
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function beforeSavePaymentInformationAndPlaceOrder(
\Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject,
$cartId,
$email,
$paymentMethod,
$billingAddress
) {
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->quoteRepository->get($quoteIdMask->getQuoteId());
$shippingAddress = $quote->getShippingAddress();
$this->modifyShippingAddress($shippingAddress, $billingAddress);
return;
}
/**
* @param $shippingAddress
* @param $billingAddress
*/
private function modifyShippingAddress($shippingAddress, $billingAddress)
{
if (!is_null($billingAddress)) {
if (!$shippingAddress->getFirstname() && $billingAddress->getFirstname()
) {
$shippingAddress->setFirstname($billingAddress->getFirstname());
}
if (!$shippingAddress->getLastname() && $billingAddress->getLastname()
) {
$shippingAddress->setLastname($billingAddress->getLastname());
}
if (!$shippingAddress->getTelephone() && $billingAddress->getTelephone()) {
$shippingAddress->setTelephone($billingAddress->getTelephone());
}
$shippingAddress->save();
}
}
} adding this to <type name="Magento\Checkout\Api\GuestPaymentInformationManagementInterface">
<plugin name="kathmandu_store_delivery_save_guest_payment_information" type="Kathmandu\StoreDelivery\Plugin\Checkout\Api\SaveGuestPaymentInformationPlugin"/>
</type> of course something similar need to be done for Hope it help you guys to find a fix in your module itself. Cheers, PS: Some payment method can need specific plugin or sometime patch, Think about Sebastien |
Preconditions
Magento Version : EE 2.2.8
Module Store Delivery Version : 1.1.2
Environment : Developer and Production Mode
Third party modules :
Steps to reproduce
Expected result
Actual result
The text was updated successfully, but these errors were encountered: