Skip to content

Commit

Permalink
Merge branch 'scandipwa:master' into 4589_confAttr
Browse files Browse the repository at this point in the history
  • Loading branch information
AzizKHAN030 authored Jun 1, 2022
2 parents 283bad4 + e6f2df4 commit d40c0ed
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
15 changes: 13 additions & 2 deletions src/Model/Resolver/ExpandedOrderResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use ScandiPWA\QuoteGraphQl\Model\Customer\CheckCustomerAccount;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Sales\Model\OrderRepository;
use Magento\Customer\Api\CustomerRepositoryInterface;

/**
* Orders data resolver
Expand All @@ -42,19 +43,27 @@ class ExpandedOrderResolver implements ResolverInterface
*/
protected $orderRepository;

/**
* @var CustomerRepositoryInterface
*/
protected $customerRepository;

/**
* @param CollectionFactoryInterface $collectionFactory
* @param CheckCustomerAccount $checkCustomerAccount
* @param OrderRepository $orderRepository
* @param CustomerRepositoryInterface $customerRepository
*/
public function __construct(
CollectionFactoryInterface $collectionFactory,
CheckCustomerAccount $checkCustomerAccount,
OrderRepository $orderRepository
OrderRepository $orderRepository,
CustomerRepositoryInterface $customerRepository
) {
$this->collectionFactory = $collectionFactory;
$this->checkCustomerAccount = $checkCustomerAccount;
$this->orderRepository = $orderRepository;
$this->customerRepository = $customerRepository;
}

/**
Expand All @@ -76,7 +85,9 @@ public function resolve(
$orderId = $args['id'];
$order = $this->orderRepository->get($orderId);

if ($customerId != $order->getCustomerId()) {
$customer = $this->customerRepository->getById($customerId);

if ($customerId !== $order->getCustomerId() && $customer->getEmail() !== $order->getCustomerEmail()) {
throw new GraphQlNoSuchEntityException(__('Customer ID is invalid.'));
}

Expand Down
17 changes: 15 additions & 2 deletions src/Model/Resolver/GetCartForCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Magento\Downloadable\Model\LinkRepository;
use Magento\Downloadable\Model\Link;
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
use Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage;

class GetCartForCustomer extends CartResolver
{
Expand Down Expand Up @@ -71,6 +72,9 @@ class GetCartForCustomer extends CartResolver
/** @var IsInStorePickupDeliveryAvailableForCartInterface */
protected $inStorePickupDeliveryAvailableForCart;

/** @var ValidationMessage */
protected $amountValidationMessage;

/**
* GetCartForCustomer constructor.
* @param ParamOverriderCustomerId $overriderCustomerId
Expand All @@ -85,6 +89,7 @@ class GetCartForCustomer extends CartResolver
* @param LinkRepository $linkRepository
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
* @param IsInStorePickupDeliveryAvailableForCartInterface $inStorePickupDeliveryAvailableForCart
* @param ValidationResultFactory $validationResultFactory
*/
public function __construct(
ParamOverriderCustomerId $overriderCustomerId,
Expand All @@ -98,7 +103,8 @@ public function __construct(
Json $serializer,
LinkRepository $linkRepository,
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId,
IsInStorePickupDeliveryAvailableForCartInterface $inStorePickupDeliveryAvailableForCart
IsInStorePickupDeliveryAvailableForCartInterface $inStorePickupDeliveryAvailableForCart,
ValidationMessage $amountValidationMessage
) {
parent::__construct(
$guestCartRepository,
Expand All @@ -115,6 +121,7 @@ public function __construct(
$this->linkRepository = $linkRepository;
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
$this->inStorePickupDeliveryAvailableForCart = $inStorePickupDeliveryAvailableForCart;
$this->amountValidationMessage = $amountValidationMessage;
}

/**
Expand Down Expand Up @@ -267,6 +274,8 @@ public function resolve(
$shipping_method = $address->getShippingMethod();
$masked_id = $this->quoteIdToMaskedQuoteId->execute(intval($cart->getId()));
$isInStorePickupAvailable = $this->inStorePickupDeliveryAvailableForCart->execute((int) $cart->getId());
$minimumOrderAmountReached = $cart->validateMinimumAmount();
$minimumOrderDescription = $this->amountValidationMessage->getMessage();

return array_merge(
$cartData,
Expand All @@ -284,7 +293,11 @@ public function resolve(
'shipping_incl_tax' => $shipping_incl_tax,
'shipping_method' => $shipping_method,
'shipping_address' => $cart->getShippingAddress(),
'is_in_store_pickup_available' => $isInStorePickupAvailable
'is_in_store_pickup_available' => $isInStorePickupAvailable,
'minimum_order_amount' => [
'minimum_order_amount_reached' => $minimumOrderAmountReached,
'minimum_order_description' => $minimumOrderDescription
]
]
);
}
Expand Down
26 changes: 22 additions & 4 deletions src/Model/Resolver/OrderListResolver.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* ScandiPWA - Progressive Web App for Magento
*
Expand All @@ -19,6 +20,7 @@
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface;
use ScandiPWA\QuoteGraphQl\Model\Customer\CheckCustomerAccount;
use Magento\Customer\Api\CustomerRepositoryInterface;

/**
* Orders data reslover
Expand All @@ -28,23 +30,32 @@ class OrderListResolver implements ResolverInterface
/**
* @var CollectionFactoryInterface
*/
private $collectionFactory;
protected $collectionFactory;

/**
* @var CheckCustomerAccount
*/
private $checkCustomerAccount;
protected $checkCustomerAccount;


/**
* @var CustomerRepositoryInterface
*/
protected $customerRepository;

/**
* @param CollectionFactoryInterface $collectionFactory
* @param CheckCustomerAccount $checkCustomerAccount
* @param CustomerRepositoryInterface $customerRepository
*/
public function __construct(
CollectionFactoryInterface $collectionFactory,
CheckCustomerAccount $checkCustomerAccount
CheckCustomerAccount $checkCustomerAccount,
CustomerRepositoryInterface $customerRepository
) {
$this->collectionFactory = $collectionFactory;
$this->checkCustomerAccount = $checkCustomerAccount;
$this->customerRepository = $customerRepository;
}

/**
Expand All @@ -63,7 +74,14 @@ public function resolve(

$this->checkCustomerAccount->execute($customerId, $context->getUserType());

$orders = $this->collectionFactory->create($customerId);
$customer = $this->customerRepository->getById($customerId);

$ordersCollection = $this->collectionFactory->create();
$ordersCollection->addFieldToFilter(
['customer_id', 'customer_email'],
[['eq' => $customerId], ['eq' => $customer->getEmail()]]
);
$orders = $ordersCollection->load();

foreach ($orders as $order) {
$trackNumbers = [];
Expand Down
6 changes: 6 additions & 0 deletions src/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ interface TotalsObject @typeResolver(class: "\\ScandiPWA\\QuoteGraphQl\\Model\\R
quote_currency_code: String
items: [TotalsItem]
is_in_store_pickup_available: Boolean
minimum_order_amount: MinimumOrderAmount
}

type TotalsItem {
Expand Down Expand Up @@ -241,6 +242,11 @@ type SelectedDownloadableLinks {
id: Int
}

type MinimumOrderAmount {
minimum_order_amount_reached: Boolean
minimum_order_description: String
}

type TotalsSegment {
code: String
title: String
Expand Down

0 comments on commit d40c0ed

Please sign in to comment.