|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?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;
- }
- }
|