PHP code example of positibe / sylius-composite-price-calculator-bundle
1. Go to this page and download the library: Download positibe/sylius-composite-price-calculator-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
positibe / sylius-composite-price-calculator-bundle example snippets
# config/bundles.php
return [
//...
Positibe\Sylius\CompositePriceCalculatorBundle\SyliusCompositePriceCalculatorBundle::class => ['all' => true]
];
$bundles = [
new \FOS\JsRoutingBundle\FOSJsRoutingBundle(),
new \Sylius\AdminOrderCreationPlugin\SyliusAdminOrderCreationPlugin(),
];
namespace Positibe\Sylius\FeePlugin\Calculator;
use Positibe\Sylius\FeePlugin\Entity\FeeableInterface;
use Sylius\Component\Core\Calculator\ProductVariantPriceCalculatorInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
class ProductVariantFeeablePriceCalculator implements ProductVariantPriceCalculatorInterface
{
//... Some stuf to get services
/**
* @param ProductVariantInterface|FeeableInterface $productVariant
* @param array $context
* @return int
*/
public function calculate(ProductVariantInterface $productVariant, array $context): int
{
$price = (int) $context['price'] ?? 0;
$fees = $productVariant->getFees();
foreach ($fees as $fee) {
if ($fee->isIncludedInPrice()) {
$price += $this->feeCalculator->calculate($context['price'], $fee);
}
}
return (int) $price;
}
}