Skip to content

Commit 7f26b19

Browse files
author
Daniil Tkachev
committed
PSPAYPAL-707 [Oxid 6] Add items to basket if 'amountToBasket' is changed
1 parent 498055f commit 7f26b19

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/Controller/ProxyController.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,15 @@ public function cancelPayPalPayment()
324324
exit;
325325
}
326326

327-
protected function addToBasket($qty = 1): void
327+
protected function addToBasket(): void
328328
{
329329
$basket = Registry::getSession()->getBasket();
330330
$utilsView = Registry::getUtilsView();
331331
$aSel = Registry::getRequest()->getRequestParameter('sel');
332+
$qty = (double)Registry::getRequest()->getRequestParameter('amountToBasket') ?? 0;
332333
if ($aid = (string)Registry::getRequest()->getRequestEscapedParameter('aid')) {
333334
try {
334-
if (!$this->itemExists($basket, $aid)) {
335+
if (!$this->itemExists($basket, $aid, $qty)) {
335336
$basket->addToBasket($aid, $qty, $aSel);
336337
$basket->isNewItemAdded();
337338
}
@@ -605,15 +606,15 @@ public function createApplepayOrder()
605606
$this->outputJson($response);
606607
}
607608

608-
private function itemExists(?Basket $basket, ?string $articleOxid): bool
609+
private function itemExists(?Basket $basket, ?string $articleOxid, ?int $amountToBasket): bool
609610
{
610611
if ($basket === null) {
611612
return false;
612613
}
613614

614615
$basketContents = $basket->getContents();
615616
foreach ($basketContents as $basketItem) {
616-
if ($basketItem->getProductId() === $articleOxid) {
617+
if ($basketItem->getProductId() === $articleOxid && $basketItem->getAmount() === $amountToBasket) {
617618
return true;
618619
}
619620
}

src/Core/ViewConfig.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ public function isPayPalSandbox(): bool
8686
*/
8787
public function isPayPalExpressSessionActive(): bool
8888
{
89-
$f = PayPalSession::isPayPalExpressOrderActive();
90-
return $f;
89+
return PayPalSession::isPayPalExpressOrderActive();
9190
}
9291

9392
/**

views/tpl/shared/paymentbuttons.tpl

+3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
}
9999
});
100100
}
101+
let amountElement = document.getElementById("amountToBasket");
102+
let amount = amountElement ? amountElement.value : 0;
103+
params.append('amountToBasket', amount);
101104
let baseUrl = '[{$sSelfLink|cat:"cl=oscpaypalproxy&fnc=createOrder&context=continue&aid="|cat:$aid|cat:"&stoken="|cat:$sToken}]';
102105
let url = baseUrl + (params.toString() ? '&' + params.toString() : '');
103106
return fetch(url , {

0 commit comments

Comments
 (0)