-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PIPRES-261: Subscription order detail view refactoring
- Loading branch information
Showing
18 changed files
with
604 additions
and
178 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Mollie\Repository; | ||
|
||
class ProductRepository extends AbstractRepository implements ProductRepositoryInterface | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(\Product::class); | ||
} | ||
|
||
public function getCombinationImageById(int $productAttributeId, int $langId): ?array | ||
{ | ||
$result = \Product::getCombinationImageById($productAttributeId, $langId); | ||
|
||
return empty($result) ? null : $result; | ||
} | ||
|
||
public function getCover(int $productId, \Context $context = null): array | ||
{ | ||
return \Product::getCover($productId, $context); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Mollie\Repository; | ||
|
||
interface ProductRepositoryInterface extends ReadOnlyRepositoryInterface | ||
{ | ||
public function getCombinationImageById(int $productAttributeId, int $langId): ?array; | ||
|
||
public function getCover(int $productId, \Context $context = null): array; | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace Mollie\Subscription\Exception; | ||
|
||
class CouldNotPresentOrderDetail extends MollieSubscriptionException | ||
{ | ||
public static function failedToFindOrder(): CouldNotPresentOrderDetail | ||
{ | ||
return new self( | ||
'Failed to find order', | ||
ExceptionCode::ORDER_FAILED_TO_FIND_ORDER | ||
); | ||
} | ||
|
||
public static function failedToFindOrderDetail(): CouldNotPresentOrderDetail | ||
{ | ||
return new self( | ||
'Failed to find order detail', | ||
ExceptionCode::ORDER_FAILED_TO_FIND_ORDER_DETAIL | ||
); | ||
} | ||
|
||
public static function failedToFindProduct(): CouldNotPresentOrderDetail | ||
{ | ||
return new self( | ||
'Failed to find product', | ||
ExceptionCode::ORDER_FAILED_TO_FIND_PRODUCT | ||
); | ||
} | ||
|
||
public static function failedToFindCurrency(): CouldNotPresentOrderDetail | ||
{ | ||
return new self( | ||
'Failed to find currency', | ||
ExceptionCode::ORDER_FAILED_TO_FIND_CURRENCY | ||
); | ||
} | ||
} |
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,130 @@ | ||
<?php | ||
|
||
namespace Mollie\Subscription\Presenter; | ||
|
||
use Mollie\Adapter\Context; | ||
use Mollie\Api\Types\SubscriptionStatus; | ||
use Mollie\Repository\CurrencyRepositoryInterface; | ||
use Mollie\Repository\OrderRepositoryInterface; | ||
use Mollie\Repository\ProductRepositoryInterface; | ||
use Mollie\Subscription\Exception\CouldNotPresentOrderDetail; | ||
use Mollie\Subscription\Repository\OrderDetailRepositoryInterface; | ||
use Mollie\Utility\NumberUtility; | ||
|
||
class OrderDetailPresenter | ||
{ | ||
/** @var OrderDetailRepositoryInterface */ | ||
private $orderDetailRepository; | ||
/** @var Context */ | ||
private $context; | ||
/** @var OrderRepositoryInterface */ | ||
private $orderRepository; | ||
/** @var ProductRepositoryInterface */ | ||
private $productRepository; | ||
/** @var CurrencyRepositoryInterface */ | ||
private $currencyRepository; | ||
|
||
public function __construct( | ||
OrderDetailRepositoryInterface $orderDetailRepository, | ||
Context $context, | ||
OrderRepositoryInterface $orderRepository, | ||
ProductRepositoryInterface $productRepository, | ||
CurrencyRepositoryInterface $currencyRepository | ||
) { | ||
$this->orderDetailRepository = $orderDetailRepository; | ||
$this->context = $context; | ||
$this->orderRepository = $orderRepository; | ||
$this->productRepository = $productRepository; | ||
$this->currencyRepository = $currencyRepository; | ||
} | ||
|
||
/** | ||
* @throws CouldNotPresentOrderDetail | ||
*/ | ||
public function present( | ||
\MolRecurringOrder $recurringOrder, | ||
\MolRecurringOrdersProduct $recurringProduct | ||
): array { | ||
$result = []; | ||
|
||
/** @var \Order|null $order */ | ||
$order = $this->orderRepository->findOneBy([ | ||
'id_order' => (int) $recurringOrder->id_order, | ||
]); | ||
|
||
if (!$order) { | ||
throw CouldNotPresentOrderDetail::failedToFindOrder(); | ||
} | ||
|
||
/** @var \OrderDetail|null $orderDetail */ | ||
$orderDetail = $this->orderDetailRepository->findOneBy([ | ||
'id_order' => (int) $recurringOrder->id_order, | ||
'product_id' => (int) $recurringProduct->id_product, | ||
'product_attribute_id' => (int) $recurringProduct->id_product_attribute, | ||
]); | ||
|
||
if (!$orderDetail) { | ||
throw CouldNotPresentOrderDetail::failedToFindOrderDetail(); | ||
} | ||
|
||
/** @var \Product|null $product */ | ||
$product = $this->productRepository->findOneBy([ | ||
'id_product' => (int) $recurringProduct->id_product, | ||
]); | ||
|
||
if (!$product) { | ||
throw CouldNotPresentOrderDetail::failedToFindProduct(); | ||
} | ||
|
||
/** @var \Currency|null $currency */ | ||
$currency = $this->currencyRepository->findOneBy([ | ||
'id_currency' => (int) $order->id_currency, | ||
]); | ||
|
||
if (!$currency) { | ||
throw CouldNotPresentOrderDetail::failedToFindCurrency(); | ||
} | ||
|
||
$linkRewrite = is_array($product->link_rewrite) && isset($product->link_rewrite[$order->id_lang]) | ||
? $product->link_rewrite[$order->id_lang] | ||
: $product->link_rewrite; | ||
|
||
$image = $this->productRepository->getCombinationImageById((int) $recurringProduct->id_product_attribute, (int) $order->id_lang); | ||
|
||
if (!$image) { | ||
$image = $this->productRepository->getCover((int) $recurringProduct->id_product); | ||
} | ||
|
||
$result['name'] = $orderDetail->product_name; | ||
$result['link'] = $this->context->getProductLink($product); | ||
$result['img'] = $this->context->getImageLink($linkRewrite, (string) $image['id_image']); | ||
$result['quantity'] = $orderDetail->product_quantity; | ||
$result['unit_price'] = $this->context->formatPrice( | ||
NumberUtility::toPrecision( | ||
(float) $orderDetail->unit_price_tax_incl, | ||
NumberUtility::DECIMAL_PRECISION | ||
), | ||
$currency->iso_code | ||
); | ||
$result['total'] = $this->context->formatPrice( | ||
NumberUtility::toPrecision( | ||
(float) $recurringOrder->total_tax_incl, | ||
NumberUtility::DECIMAL_PRECISION | ||
), | ||
$currency->iso_code | ||
); | ||
|
||
$result['status'] = $recurringOrder->status; | ||
$result['start_date'] = $recurringOrder->date_add; | ||
|
||
if ($recurringOrder->status === SubscriptionStatus::STATUS_ACTIVE) { | ||
$result['next_payment_date'] = $recurringOrder->next_payment; | ||
} | ||
|
||
if ($recurringOrder->status === SubscriptionStatus::STATUS_CANCELED) { | ||
$result['cancelled_date'] = $recurringOrder->cancelled_at; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.