1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace MarketplaceRepository;
- class ProductRepository
- extends Repository
- implements \Core\App\Repository\Marketplace\ProductInterface
- {
- public function getAll($withOutDiscount = false)
- {
- $productFactory = new \Core\App\Factory\ProductFactory();
- $productFactory->setPrefix(self::PREFIX);
- $results = array();
-
- $taxRate = $this->getTax();
- $currency = $this->getCurrency();
- $taxIncluded = $this->areTaxesIncluded();
-
- $products = $this->getProducts();
- if(!empty($products))
- {
- foreach($products as $product)
- {
- if(isset($product['variants']) && !empty($product['variants']))
- {
- foreach($product['variants'] as $variant)
- {
- $finalPrice = $variant['price'];
- if($withOutDiscount && ($variant['compare_at_price'] > $variant['price']))
- {
- $finalPrice = $variant['compare_at_price'];
- }
- $productObj = $productFactory->createProduct(
- $product['id'] . '_' . $variant['id'],
- $product['title'] . ' - ' . $variant['title'],
- '',
- $variant['sku'],
- $currency,
- $finalPrice,
- ($variant['taxable'] == 1) ? $taxRate : 0,
- $this->getProdTip($product['published_at']),
- $taxIncluded
- );
- $results[] = $productObj;
- }
- }
- }
- }
- return $results;
- }
- private function getProdTip($published_at)
- {
- if(!empty($published_at))
- {
- return 'produs';
- }
- else
- {
- return 'inactiv';
- }
- }
- }
|