-
Notifications
You must be signed in to change notification settings - Fork 44
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
PIPRES-338: Mixed cart subscription listing improvements #812
Merged
mandan2
merged 5 commits into
develop
from
PIPRES-338-mixed-cart-subscription-listing-improvements
Sep 19, 2023
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8a7f971
PIPRES-338: Mixed cart subscription listing improvements
mandan2 47a0462
added rounding for total price and moved part of install improvements…
mandan2 176c63c
fix
mandan2 1a4feb0
added mandate_id append to upgrade file too
mandan2 44f1eea
fix
mandan2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Mollie\Subscription\Presenter; | ||
|
||
class OrderPresenter | ||
{ | ||
public function present( | ||
\Order $order, | ||
int $recurringOrderProductAttributeId, | ||
float $recurringOrderTotalTaxIncl | ||
): RecurringOrderLazyArray { | ||
$orderProducts = $order->getCartProducts(); | ||
|
||
foreach ($orderProducts as $orderProduct) { | ||
if ((int) $orderProduct['id_product_attribute'] !== $recurringOrderProductAttributeId) { | ||
$order->total_paid_tax_excl -= (float) $orderProduct['total_price_tax_excl']; | ||
|
||
continue; | ||
} | ||
|
||
$order->total_products = (float) $orderProduct['total_price_tax_excl']; | ||
$order->total_products_wt = (float) $orderProduct['total_price_tax_incl']; | ||
$order->total_paid_tax_incl = $recurringOrderTotalTaxIncl; | ||
$order->total_paid = $recurringOrderTotalTaxIncl; | ||
|
||
break; | ||
} | ||
|
||
$orderLazyArray = new RecurringOrderLazyArray($order); | ||
|
||
$orderLazyArray->setRecurringOrderProductAttributeId($recurringOrderProductAttributeId); | ||
|
||
return $orderLazyArray; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Mollie\Subscription\Presenter; | ||
|
||
use PrestaShop\PrestaShop\Adapter\Presenter\Order\OrderLazyArray; | ||
|
||
class RecurringOrderLazyArray extends OrderLazyArray | ||
{ | ||
/** @var int */ | ||
private $recurringOrderProductAttributeId; | ||
|
||
public function setRecurringOrderProductAttributeId(int $recurringOrderProductAttributeId): void | ||
{ | ||
$this->recurringOrderProductAttributeId = $recurringOrderProductAttributeId; | ||
} | ||
|
||
/** | ||
* @arrayAccess | ||
* | ||
* @return array | ||
*/ | ||
public function getProducts(): array | ||
{ | ||
$subscriptionProduct = []; | ||
|
||
$orderProducts = parent::getProducts(); | ||
|
||
foreach ($orderProducts as $orderProduct) { | ||
if ((int) $orderProduct['id_product_attribute'] !== $this->recurringOrderProductAttributeId) { | ||
continue; | ||
} | ||
|
||
$subscriptionProduct[] = $orderProduct; | ||
|
||
break; | ||
} | ||
|
||
return $subscriptionProduct; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,15 @@ | |
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Subscription\Logger; | ||
namespace Mollie\Subscription\Presenter; | ||
|
||
use Currency; | ||
use Mollie\Adapter\Language; | ||
use Mollie\Subscription\Api\MethodApi; | ||
use Mollie\Subscription\Repository\RecurringOrderRepositoryInterface; | ||
use Mollie\Subscription\Repository\RecurringOrdersProductRepositoryInterface; | ||
use Mollie\Utility\NumberUtility; | ||
use Order; | ||
use PrestaShop\PrestaShop\Adapter\Presenter\Order\OrderPresenter; | ||
use Product; | ||
|
||
class RecurringOrderPresenter | ||
|
@@ -23,17 +23,21 @@ class RecurringOrderPresenter | |
private $language; | ||
/** @var MethodApi */ | ||
private $methodApi; | ||
/** @var OrderPresenter */ | ||
private $orderPresenter; | ||
|
||
public function __construct( | ||
RecurringOrderRepositoryInterface $recurringOrderRepository, | ||
RecurringOrdersProductRepositoryInterface $recurringOrdersProductRepository, | ||
Language $language, | ||
MethodApi $methodApi | ||
MethodApi $methodApi, | ||
OrderPresenter $orderPresenter | ||
) { | ||
$this->recurringOrderRepository = $recurringOrderRepository; | ||
$this->recurringOrdersProductRepository = $recurringOrdersProductRepository; | ||
$this->language = $language; | ||
$this->methodApi = $methodApi; | ||
$this->orderPresenter = $orderPresenter; | ||
} | ||
|
||
public function present(int $recurringOrderId): array | ||
|
@@ -56,7 +60,11 @@ public function present(int $recurringOrderId): array | |
$recurringOrderData['recurring_order'] = $recurringOrder; | ||
$recurringOrderData['recurring_product'] = $recurringProduct; | ||
$recurringOrderData['product'] = $product; | ||
$recurringOrderData['order'] = (new OrderPresenter())->present($order); | ||
$recurringOrderData['order'] = $this->orderPresenter->present( | ||
$order, | ||
(int) $recurringProduct->id_product_attribute, | ||
NumberUtility::toPrecision((float) $recurringOrder->total_tax_incl, 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. constant intead of number |
||
); | ||
$recurringOrderData['payment_methods'] = $this->methodApi->getMethodsForFirstPayment($this->language->getContextLanguage()->locale, $currency->iso_code); | ||
|
||
return $recurringOrderData; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it really extend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using theme's existing template
customer/_partials/order-detail-no-return.tpl
and OrderLazyArray for this template is needed. Extension makes sens as we don't need to change other methods, only the ones we need to manipulate.