|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
-
- namespace Lc\CaracoleBundle\Solver\Order;
-
- use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
- use Lc\CaracoleBundle\Solver\Price\PriceSolver;
- use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
- use Lc\CaracoleBundle\Solver\Product\ProductSolver;
-
- class OrderProductSolver
- {
- protected ProductSolver $productSolver;
- protected ProductFamilySolver $productFamilySolver;
- protected OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver;
- protected PriceSolver $priceSolver;
-
- public function __construct(
- ProductSolver $productSolver,
- ProductFamilySolver $productFamilySolver,
- OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver,
- PriceSolver $priceSolver
- ) {
- $this->productSolver = $productSolver;
- $this->productFamilySolver = $productFamilySolver;
- $this->orderProductReductionCatalogSolver = $orderProductReductionCatalogSolver;
- $this->priceSolver = $priceSolver;
- }
-
- public function compare(OrderProductInterface $orderProduct1, OrderProductInterface $orderProduct2)
- {
- return $orderProduct1->getProduct()->getId() == $orderProduct2->getProduct()->getId()
- && $orderProduct1->getRedelivery() == $orderProduct2->getRedelivery()
- && (string)$this->priceSolver->getPrice($orderProduct1)
- == (string)$this->priceSolver->getPrice($orderProduct2)
- && $this->orderProductReductionCatalogSolver->compare(
- $orderProduct1->getOrderProductReductionCatalog(),
- $orderProduct2->getOrderProductReductionCatalog()
- );
- }
-
- // groupOrderProductsByProductFamily
- public function getOrderProductsByProductFamily(array $orderProducts): array
- {
- $orderProductsByProductFamily = [];
- foreach ($orderProducts as $orderProduct) {
- if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
- $productFamily = $orderProduct->getProduct()->getProductFamily();
- if (!isset($orderProductsByProductFamily[$productFamily->getId()])) {
- $orderProductsByProductFamily[$productFamily->getId()] = [
- 'order_products' => [],
- 'total_quantity_weight' => 0,
- ];
- }
- $orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct;
- $orderProductsByProductFamily[$productFamily->getId(
- )]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit(
- )->getCoefficient()) * $orderProduct->getQuantityOrder();
- }
- }
-
- return $orderProductsByProductFamily;
- }
-
- // getOrderProductsFormOrderShopsGroupByStorageOrder
- public function getOrderProductsByOrderShopsGroupByStorageOrder(array $orderShops): array
- {
- $orderProductsByStorageOrder = [];
-
- foreach ($orderShops as $orderShop) {
- foreach ($orderShop->getOrderProducts() as $orderProduct) {
- if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
- $productFamily = $orderProduct->getProduct()->getProductFamily();
- $storageOrder = 0;
-
- if ($productFamily->getStorageOrder()) {
- $storageOrder = $productFamily->getStorageOrder();
- }
-
- if (!isset($orderProductsByStorageOrder[$storageOrder])) {
- $orderProductsByStorageOrder[$productFamily->getId()] = [
- 'order_products' => [],
- 'total_quantity_weight' => 0,
- ];
- }
-
- $orderProductsByStorageOrder[$storageOrder]['order_products'][] = $orderProduct;
- $orderProductsByStorageOrder[$storageOrder]['total_quantity_weight'] += ($orderProduct->getQuantityProduct(
- ) / $orderProduct->getUnit()->getCoefficient()) * $orderProduct->getQuantityOrder();
- }
- }
- }
-
- return $orderProductsByStorageOrder;
- }
-
- public function getTitleOrderShop(OrderProductInterface $orderProduct)
- {
- $product = $orderProduct->getProduct();
- $productFamily = $product->getProductFamily();
-
- $titleProduct = $product->getTitle();
- $titleProductFamily = $productFamily->getTitle();
-
- if (strlen($titleProduct) > 0 && strlen($titleProductFamily) > 0) {
- $title = $titleProductFamily . ' - ' . $titleProduct;
- } else {
- $title = strlen($titleProduct) ? $titleProduct : $titleProductFamily;
- }
-
- if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) {
- $title .= ' - ' . $this->productSolver->getQuantityLabelInherited($product);
- }
-
- return $title;
- }
-
- public function getTitleProduct(OrderProductInterface $orderProduct): string
- {
- $product = $orderProduct->getProduct();
- $productFamily = $product->getProductFamily();
- $title = ($product->getTitle() && strlen($product->getTitle()) > 0) ? $product->getTitle() : '';
-
- if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) {
- if(strlen($title) > 0) {
- $title .= ' - ';
- }
- $title .= $this->productSolver->getQuantityLabelInherited($product);
- }
-
- return $title;
- }
-
- public function getTitleSummaryAfterAddCart(OrderProductInterface $orderProduct)
- {
- $title = '';
-
- $product = $orderProduct->getProduct();
- $productFamily = $product->getProductFamily();
- $titleProduct = $this->productSolver->getTitleInherited($product);
- $titleProductFamily = $productFamily->getTitle();
-
- // multiple
- if ($productFamily->getActiveProducts() && $productFamily->getBehaviorAddToCart() == 'multiple') {
- $title .= $titleProduct;
- if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) {
- $title .= ' - ' . $this->productSolver->getQuantityLabelInherited($product);
- }
- }
-
- // simple
- if ($productFamily->getBehaviorAddToCart() == 'simple') {
-
- if($orderProduct->getOrderPackProduct()) {
- $title .= $this->productFamilySolver->getTitleProduct($product);
- }
- else {
- if ($productFamily->getActiveProducts()) {
- $title .= $titleProduct;
- if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) {
- $title .= ' - ' . $this->productSolver->getQuantityLabelInherited($product);
- }
- }
- }
- }
-
- return $title;
- }
- }
|