Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

91 line
3.2KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Product;
  3. use App\Entity\Product\ProductFamily;
  4. use App\Solver\Product\ProductFamilySectionPropertySolver;
  5. use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
  6. use Lc\CaracoleBundle\Repository\SectionStoreTrait;
  7. use Lc\CaracoleBundle\Repository\AbstractStore;
  8. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  9. class ProductStore extends AbstractStore
  10. {
  11. use SectionStoreTrait;
  12. use MerchantStoreTrait;
  13. protected ProductRepositoryQuery $query;
  14. protected ProductFamilySectionPropertySolver $productFamilySectionPropertySolver;
  15. public function __construct(ProductRepositoryQuery $query, ProductFamilySectionPropertySolver $productFamilySectionPropertySolver)
  16. {
  17. $this->query = $query;
  18. $this->productFamilySectionPropertySolver = $productFamilySectionPropertySolver;
  19. }
  20. public function orderByDefault(RepositoryQueryInterface $query) :RepositoryQueryInterface
  21. {
  22. return $query;
  23. }
  24. public function filtersDefault($query):RepositoryQueryInterface
  25. {
  26. $this->addFilterBySectionOptionnal($query);
  27. $this->addFilterByMerchantViaSectionOptionnal($query);
  28. $query->filterIsOnlineAndOffline();
  29. return $query;
  30. }
  31. public function relationsDefault($query):RepositoryQueryInterface
  32. {
  33. return $query->joinProductFamily();
  34. }
  35. //findProductByAvailabilitiesNegative
  36. public function getByAvailabilitiesNegative(ProductRepositoryQuery $query = null): array
  37. {
  38. $query = $this->createDefaultQuery($query);
  39. $query->filterIsOnline();
  40. $query->filterAvailableQuantityNegative();
  41. $query->groupBy('productFamily.id');
  42. $productListAvailableQuantityNegative = $query->find();
  43. foreach ($productListAvailableQuantityNegative as $i=>$product) {
  44. if(!$this->productFamilySectionPropertySolver->useBehaviorStockAvailableQuantity($product->getProductfamily())){
  45. unset($productListAvailableQuantityNegative[$i]);
  46. }
  47. }
  48. return $productListAvailableQuantityNegative;
  49. }
  50. public function getByAvailabilitiesSupplierNegative(ProductRepositoryQuery $query = null): array
  51. {
  52. $query = $this->createDefaultQuery($query);
  53. $query->joinProductFamily();
  54. $query->filterIsOnline();
  55. $query->filterAvailableQuantitySupplierNegative();
  56. $query->filterIsNotAvailableQuantitySupplierUnlimited();
  57. $query->groupBy('productFamily.id');
  58. $productListAvailableQuantityNegative = $query->find();
  59. foreach ($productListAvailableQuantityNegative as $i=>$product) {
  60. if(!$this->productFamilySectionPropertySolver->useBehaviorStockAvailableQuantitySupplier($product->getProductfamily())){
  61. unset($productListAvailableQuantityNegative[$i]);
  62. }
  63. }
  64. return $productListAvailableQuantityNegative;
  65. }
  66. public function getOriginByProductFamily(ProductFamily $productFamily, ProductRepositoryQuery $query = null): array
  67. {
  68. $query = $this->createQuery();
  69. $query->filterByProductFamily($productFamily);
  70. $query->filterIsOriginProduct();
  71. return $query->find();
  72. }
  73. }