You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.8KB

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