1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace Core\FacturisRepository;
- class ProductRepository
- extends Repository
- implements \Core\App\Repository\Facturis\ProductInterface
- {
- public $products;
- public function __construct($apiKey, $username, $password, $fiscalCode)
- {
- parent::__construct($apiKey, $username, $password, $fiscalCode);
- $this->products = $this->getProducts();
- }
- public function add(\Core\App\Entity\Product $product)
- {
- if($this->isNewProduct($product))
- {
- $product = (array)$product;
- $response = $this->insertProduct($product);
- if(isset($response['warning']) && $response['warning'] && isset($response['msg']))
- {
- throw new \Exception($response['msg']);
- }
- }
- }
- public function isNewProduct(\Core\App\Entity\Product $product)
- {
- if(!empty($product->getProdCod1()) && in_array($product->getProdCod1(), array_column($this->products, 'Alt_Cod')))
- return false;
- if(!empty($product->getProdCod()) && in_array($product->getProdCod(), array_column($this->products, 'Cod_EAN')))
- return false;
- if(!empty($product->getProdSku()) && in_array($product->getProdSku(), array_column($this->products, 'Cod_SKU')))
- return false;
- if(!empty($product->getProdNume()) && in_array($product->getProdNume(), array_column($this->products, 'Denumire')))
- return false;
- return true;
- }
- public function getAll()
- {
- $response = $this->getProducts();
- return $response;
- }
- }
|