for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Core\OrderProcessing;
use Sylius\Component\Core\Calculator\ProductVariantPriceCalculatorInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Order\Model\OrderInterface as BaseOrderInterface;
use Sylius\Component\Order\Processor\OrderProcessorInterface;
use Webmozart\Assert\Assert;
/**
* @author Mateusz Zalewski <[email protected]>
final class OrderPricesRecalculator implements OrderProcessorInterface
{
* @var ProductVariantPriceCalculatorInterface
private $productVariantPriceCalculator;
* @param ProductVariantPriceCalculatorInterface $productVariantPriceCalculator
public function __construct(ProductVariantPriceCalculatorInterface $productVariantPriceCalculator)
$productVariantPriceCalculator
20
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.
$this->productVariantPriceCalculator = $productVariantPriceCalculator;
}
* {@inheritdoc}
public function process(BaseOrderInterface $order)
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);
$channel = $order->getChannel();
foreach ($order->getItems() as $item) {
if ($item->isImmutable()) {
continue;
$item->setUnitPrice($this->productVariantPriceCalculator->calculate(
$item->getVariant(),
['channel' => $channel]
));
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.