Skip to content

Commit

Permalink
Merge pull request #2 from mageworx/fix_remove_delivery_date
Browse files Browse the repository at this point in the history
Fix for removing delivery date data
  • Loading branch information
SiarheyUchukhlebau authored Mar 29, 2023
2 parents 857a84a + 3ec294a commit f9d33b8
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions Model/Resolver/RemoveDeliveryDateFromCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
use MageWorx\DeliveryDate\Api\QueueManagerInterface;
use MageWorx\DeliveryDate\Api\Repository\QueueRepositoryInterface;
Expand All @@ -34,19 +35,27 @@ class RemoveDeliveryDateFromCart implements \Magento\Framework\GraphQl\Query\Res
*/
protected $getCartForUser;

/**
* @var CartRepositoryInterface
*/
protected $cartRepository;

/**
* @param QueueManagerInterface $queueManager
* @param QueueRepositoryInterface $queueRepository
* @param GetCartForUser $getCartForUser
* @param CartRepositoryInterface $cartRepository
*/
public function __construct(
QueueManagerInterface $queueManager,
QueueRepositoryInterface $queueRepository,
GetCartForUser $getCartForUser
GetCartForUser $getCartForUser,
CartRepositoryInterface $cartRepository
) {
$this->queueManager = $queueManager;
$this->queueRepository = $queueRepository;
$this->getCartForUser = $getCartForUser;
$this->cartRepository = $cartRepository;
}

/**
Expand Down Expand Up @@ -76,8 +85,14 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
// Delivery date has been not set, nothing to do
}

$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);
$shippingAddress = $cart->getShippingAddress();
if ($shippingAddress instanceof \Magento\Quote\Api\Data\AddressInterface) {
$this->queueManager->cleanDeliveryDateDataByQuoteAddress($shippingAddress);
$shippingAddress->setCollectShippingRates(true)->collectShippingRates();
$this->cartRepository->save($cart);
}

return [
'model' => $cart
Expand Down

0 comments on commit f9d33b8

Please sign in to comment.