Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 18b716e

Browse files
omiroshnichenkoVolodymyr Kublytskyi
authored and
Volodymyr Kublytskyi
committed
MAGETWO-84321: Instant Purchase button displays only for one store view
1 parent 5fcde49 commit 18b716e

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

app/code/Magento/InstantPurchase/Model/PlaceOrder.php

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use Magento\InstantPurchase\Model\QuoteManagement\QuoteCreation;
1414
use Magento\InstantPurchase\Model\QuoteManagement\QuoteFilling;
1515
use Magento\InstantPurchase\Model\QuoteManagement\ShippingConfiguration;
16+
use Magento\Quote\Api\CartRepositoryInterface;
1617
use Magento\Store\Model\Store;
18+
use \Throwable;
1719

1820
/**
1921
* Place an order using instant purchase option.
@@ -22,6 +24,11 @@
2224
*/
2325
class PlaceOrder
2426
{
27+
/**
28+
* @var CartRepositoryInterface
29+
*/
30+
private $quoteRepository;
31+
2532
/**
2633
* @var QuoteCreation
2734
*/
@@ -49,19 +56,22 @@ class PlaceOrder
4956

5057
/**
5158
* PlaceOrder constructor.
59+
* @param CartRepositoryInterface $quoteRepository
5260
* @param QuoteCreation $quoteCreation
5361
* @param QuoteFilling $quoteFilling
5462
* @param ShippingConfiguration $shippingConfiguration
5563
* @param PaymentConfiguration $paymentConfiguration
5664
* @param Purchase $purchase
5765
*/
5866
public function __construct(
67+
CartRepositoryInterface $quoteRepository,
5968
QuoteCreation $quoteCreation,
6069
QuoteFilling $quoteFilling,
6170
ShippingConfiguration $shippingConfiguration,
6271
PaymentConfiguration $paymentConfiguration,
6372
Purchase $purchase
6473
) {
74+
$this->quoteRepository = $quoteRepository;
6575
$this->quoteCreation = $quoteCreation;
6676
$this->quoteFilling = $quoteFilling;
6777
$this->shippingConfiguration = $shippingConfiguration;
@@ -79,6 +89,7 @@ public function __construct(
7989
* @param array $productRequest
8090
* @return int order identifier
8191
* @throws LocalizedException if order can not be placed.
92+
* @throws Throwable if unpredictable error occurred.
8293
*/
8394
public function placeOrder(
8495
Store $store,
@@ -98,17 +109,28 @@ public function placeOrder(
98109
$product,
99110
$productRequest
100111
);
101-
$quote = $this->shippingConfiguration->configureShippingMethod(
102-
$quote,
103-
$instantPurchaseOption->getShippingMethod()
104-
);
105-
$quote = $this->paymentConfiguration->configurePayment(
106-
$quote,
107-
$instantPurchaseOption->getPaymentToken()
108-
);
109-
$orderId = $this->purchase->purchase(
110-
$quote
111-
);
112-
return $orderId;
112+
113+
$quote->collectTotals();
114+
$this->quoteRepository->save($quote);
115+
$quote = $this->quoteRepository->get($quote->getId());
116+
117+
try {
118+
$quote = $this->shippingConfiguration->configureShippingMethod(
119+
$quote,
120+
$instantPurchaseOption->getShippingMethod()
121+
);
122+
$quote = $this->paymentConfiguration->configurePayment(
123+
$quote,
124+
$instantPurchaseOption->getPaymentToken()
125+
);
126+
$orderId = $this->purchase->purchase(
127+
$quote
128+
);
129+
return $orderId;
130+
} catch (Throwable $e) {
131+
$quote->setIsActive(false);
132+
$this->quoteRepository->save($quote);
133+
throw $e;
134+
}
113135
}
114136
}

0 commit comments

Comments
 (0)