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.

OrderProductStore.php 1.7KB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Order;
  3. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  4. use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
  5. use Lc\CaracoleBundle\Model\Product\ProductInterface;
  6. use Lc\CaracoleBundle\Repository\SectionStoreTrait;
  7. use Lc\SovBundle\Repository\AbstractStore;
  8. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  9. class OrderProductStore extends AbstractStore
  10. {
  11. use SectionStoreTrait;
  12. protected OrderProductRepositoryQuery $query;
  13. public function __construct(OrderProductRepositoryQuery $query)
  14. {
  15. $this->query = $query;
  16. }
  17. public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  18. {
  19. $query->orderBy('id');
  20. return $query;
  21. }
  22. public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  23. {
  24. if($this->section) {
  25. $query->filterBySection($this->section);
  26. }
  27. return $query;
  28. }
  29. public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  30. {
  31. return $query;
  32. }
  33. // findGiftVouchersByOrder
  34. public function getGiftVouchersByOrder(OrderShopInterface $orderShop): array
  35. {
  36. $query = $this->createQuery();
  37. $query
  38. ->filterByOrderShop($orderShop)
  39. ->filterIsGiftVoucherActive();
  40. return $query->find();
  41. }
  42. // findOrderProductsInCartsByProduct
  43. public function getInCartsByProduct(ProductInterface $product, $query = null): array
  44. {
  45. $query = $this->createDefaultQuery($query);
  46. $query->filterByProduct($product);
  47. $query->filterByOrderStatus(OrderStatusModel::$statusAliasAsValid);
  48. return $query->find();
  49. }
  50. }