ProductRepository.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace MarketplaceRepository;
  3. class ProductRepository
  4. extends Repository
  5. implements \Core\App\Repository\Marketplace\ProductInterface
  6. {
  7. public function getAll($withOutDiscount = false)
  8. {
  9. $productFactory = new \Core\App\Factory\ProductFactory();
  10. $productFactory->setPrefix(self::PREFIX);
  11. $results = array();
  12. $taxRate = $this->getTax();
  13. $currency = $this->getCurrency();
  14. $taxIncluded = $this->areTaxesIncluded();
  15. $products = $this->getProducts();
  16. if(!empty($products))
  17. {
  18. foreach($products as $product)
  19. {
  20. if(isset($product['variants']) && !empty($product['variants']))
  21. {
  22. foreach($product['variants'] as $variant)
  23. {
  24. $finalPrice = $variant['price'];
  25. if($withOutDiscount && ($variant['compare_at_price'] > $variant['price']))
  26. {
  27. $finalPrice = $variant['compare_at_price'];
  28. }
  29. $productObj = $productFactory->createProduct(
  30. $product['id'] . '_' . $variant['id'],
  31. $product['title'] . ' - ' . $variant['title'],
  32. '',
  33. $variant['sku'],
  34. $currency,
  35. $finalPrice,
  36. ($variant['taxable'] == 1) ? $taxRate : 0,
  37. $this->getProdTip($product['published_at']),
  38. $taxIncluded
  39. );
  40. $results[] = $productObj;
  41. }
  42. }
  43. }
  44. }
  45. return $results;
  46. }
  47. private function getProdTip($published_at)
  48. {
  49. if(!empty($published_at))
  50. {
  51. return 'produs';
  52. }
  53. else
  54. {
  55. return 'inactiv';
  56. }
  57. }
  58. }