Skip to content
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

[QuantityRules] merge ItemQuantityRangePriceProcessor with CartItemsProcessor #813

Merged
merged 1 commit into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
class: CoreShop\Component\Core\Order\Processor\CartItemsProcessor
arguments:
- '@coreshop.order.purchasable.calculator'
- '@coreshop.product_quantity_price_rules.detector.quantity_reference'
- '@coreshop.cart_item.processor'
tags:
- { name: coreshop.cart_processor, priority: 600 }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
services:
coreshop.cart_processor.items_quantity_range_price:
class: CoreShop\Component\Core\Order\Processor\CartItemQuantityRangePriceProcessor
decorates: coreshop.cart_processor.items
decoration_inner_name: coreshop.cart_processor.items.inner
arguments:
- '@coreshop.cart_processor.items.inner'
- '@coreshop.order.purchasable.calculator'
- '@coreshop.product_quantity_price_rules.detector.quantity_reference'
- '@coreshop.cart_item.processor'
tags:
- { name: coreshop.cart_processor, priority: 580 }

coreshop.product_quantity_price_rules.rule.condition.customers:
class: CoreShop\Component\Core\Product\Rule\Condition\CustomersConditionChecker
tags:
Expand Down

This file was deleted.

20 changes: 20 additions & 0 deletions src/CoreShop/Component/Core/Order/Processor/CartItemsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use CoreShop\Component\Order\Model\CartInterface;
use CoreShop\Component\Order\Processor\CartItemProcessorInterface;
use CoreShop\Component\Order\Processor\CartProcessorInterface;
use CoreShop\Component\ProductQuantityPriceRules\Detector\QuantityReferenceDetectorInterface;
use CoreShop\Component\ProductQuantityPriceRules\Exception\NoPriceFoundException;
use CoreShop\Component\ProductQuantityPriceRules\Exception\NoRuleFoundException;
use Webmozart\Assert\Assert;

final class CartItemsProcessor implements CartProcessorInterface
Expand All @@ -27,20 +30,28 @@ final class CartItemsProcessor implements CartProcessorInterface
*/
private $productPriceCalculator;

/**
* @var QuantityReferenceDetectorInterface
*/
private $quantityReferenceDetector;

/**
* @var CartItemProcessorInterface
*/
private $cartItemProcessor;

/**
* @param PurchasableCalculatorInterface $productPriceCalculator
* @param QuantityReferenceDetectorInterface $quantityReferenceDetector
* @param CartItemProcessorInterface $cartItemProcessor
*/
public function __construct(
PurchasableCalculatorInterface $productPriceCalculator,
QuantityReferenceDetectorInterface $quantityReferenceDetector,
CartItemProcessorInterface $cartItemProcessor
) {
$this->productPriceCalculator = $productPriceCalculator;
$this->quantityReferenceDetector = $quantityReferenceDetector;
$this->cartItemProcessor = $cartItemProcessor;
}

Expand Down Expand Up @@ -84,6 +95,15 @@ public function process(CartInterface $cart)
$product = $item->getProduct();

$itemPrice = $this->productPriceCalculator->getPrice($product, $context, true);

try {
$itemPrice = $this->quantityReferenceDetector->detectQuantityPrice($item->getProduct(), $item->getQuantity(), $itemPrice, $context);
} catch (NoRuleFoundException $exception) {

} catch (NoPriceFoundException $exception) {

}

$itemPriceWithoutDiscount = $this->productPriceCalculator->getPrice($product, $context);
$itemRetailPrice = $this->productPriceCalculator->getRetailPrice($product, $context);
$itemDiscountPrice = $this->productPriceCalculator->getDiscountPrice($product, $context);
Expand Down