Skip to content

Commit

Permalink
Merge pull request #813 from dpfaffenbauer/quantity-rules-part2
Browse files Browse the repository at this point in the history
[QuantityRules] merge ItemQuantityRangePriceProcessor with CartItemsProcessor
  • Loading branch information
dpfaffenbauer authored Feb 13, 2019
2 parents 45453c8 + b400882 commit 5dbd8b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 128 deletions.
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

0 comments on commit 5dbd8b1

Please sign in to comment.