- <?php
-
- namespace Lc\CaracoleBundle\Solver\Product;
-
- use Doctrine\Common\Collections\ArrayCollection;
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
- use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
- use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
- use Lc\CaracoleBundle\Model\Product\ProductInterface;
-
- class ProductSolver
- {
-
- public function isProductSaleStatusOn(ProductInterface $product)
- {
- if ($product->getProductFamily()->getSaleStatus() != 1) {
- return false;
- }
-
- $allCategoriesSalesOff = true;
- $unavailableSpecificDay = false;
-
- foreach ($product->getProductFamily()->getProductCategories() as $category) {
- if ($category->getParent()) {
- if ($category->getSaleStatus() && $category->getParent()->getSaleStatus()) {
- $allCategoriesSalesOff = false;
- }
- } else {
- if ($category->getSaleStatus()) {
- $allCategoriesSalesOff = false;
- }
- }
-
- // specific day
- // @TODO : spécifique pdl ?
- $displaySpecificDay = $category->getDisplaySpecificDay();
- if ($displaySpecificDay && $displaySpecificDay != date('N')) {
- $unavailableSpecificDay = true;
- }
- }
-
- if ($allCategoriesSalesOff) {
- return false;
- }
-
- if ($unavailableSpecificDay) {
- return false;
- }
-
- return true;
- }
-
- // getProductQuantity
- public function getProductQuantity(ProductInterface $product)
- {
- $productFamily = $product->getProductFamily();
-
- if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
- return $this->getQuantityInherited($product) / $this->getUnitInherited($product)->getCoefficient();
- } else {
- return 1;
- }
- }
-
- public function getBuyingPriceInherited(ProductInterface $product)
- {
- if ($product->getBuyingPrice()) {
- return $product->getBuyingPrice();
- } else {
- return $product->getProductFamily()->getBuyingPrice();
- }
- }
-
- public function getBuyingPriceByRefUnitInherited(ProductInterface $product)
- {
- if ($product->getBuyingPriceByRefUnit()) {
- return $product->getBuyingPriceByRefUnit();
- } else {
- return $product->getProductFamily()->getBuyingPriceByRefUnit();
- }
- }
-
- public function getPriceInherited(ProductInterface $product)
- {
- if ($product->getPrice()) {
- return $product->getPrice();
- } else {
- return $product->getProductFamily()->getPrice();
- }
- }
-
- public function getPriceByRefUnitInherited(ProductInterface $product)
- {
- if ($product->getPriceByRefUnit()) {
- return $product->getPriceByRefUnit();
- } else {
- return $product->getProductFamily()->getPriceByRefUnit();
- }
- }
-
- public function getBehaviorPriceInherited(ProductInterface $product)
- {
- return $product->getProductFamily()->getBehaviorPrice();
- }
-
- public function getReductionCatalogInherited(ProductInterface $product)
- {
- return $product->getProductFamily()->getReductionCatalog();
- }
-
- public function getUnitInherited(ProductInterface $product)
- {
- if ($product->getUnit()) {
- return $product->getUnit();
- } else {
- return $product->getProductFamily()->getUnit();
- }
- }
-
- public function getTitleInherited(ProductInterface $product)
- {
- if ($product->getTitle()) {
- return $product->getTitle();
- } else {
- return $product->getProductFamily()->getTitle();
- }
- }
-
- public function getQuantityInherited(ProductInterface $product)
- {
- if ($product->getQuantity()) {
- return $product->getQuantity();
- } else {
- return $product->getProductFamily()->getQuantity();
- }
- }
-
- public function getQuantityLabelInherited(ProductInterface $product)
- {
- $quantity = $this->getQuantityInherited($product);
- $unit = $this->getUnitInherited($product);
- return $quantity . $unit->getWordingShort();
- }
-
- public function getAvailableQuantityInherited(ProductInterface $product)
- {
- switch ($product->getProductFamily()->getBehaviorCountStock()) {
- case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
- case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
- return $product->getProductFamily()->getAvailableQuantity();
- case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
- return $product->getAvailableQuantity();
- }
- }
-
- public function getAvailableQuantityDefaultInherited(ProductInterface $product)
- {
- switch ($product->getProductFamily()->getBehaviorCountStock()) {
- case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
- case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
- return $product->getProductFamily()->getAvailableQuantityDefault();
- case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
- return $product->getAvailableQuantityDefault();
- }
- }
-
- public function getAvailableQuantitySupplierInherited(ProductInterface $product)
- {
- switch ($product->getProductFamily()->getBehaviorCountStock()) {
- case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
- case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
- return $product->getProductFamily()->getAvailableQuantitySupplier();
- case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
- return $product->getAvailableQuantitySupplier();
- }
- }
-
-
- /*public function getTaxRateInherited(ProductInterface $product)
- {
- return $product->getProductFamily()->getTaxRateInherited();
- }*/
-
- public function getExportTitleInherited(ProductInterface $product): ?string
- {
- $exportTitle = $product->getExportTitle();
- if ($exportTitle && strlen($exportTitle)) {
- return $exportTitle;
- } else {
- $productFamily = $product->getProductFamily();
- if ($productFamily) {
- return $productFamily->getExportTitle();
- }
- }
-
- return null;
- }
-
- public function getExportNoteInherited(ProductInterface $product): ?string
- {
- $exportNote = $product->getExportNote();
- if ($exportNote && strlen($exportNote)) {
- return $exportNote;
- } else {
- $productFamily = $product->getProductFamily();
- if ($productFamily) {
- return $productFamily->getExportNote();
- }
- }
-
- return null;
- }
- }
|