示例#1
0
 /**
  * {@inheritdoc}
  */
 public function update(EntityInterface $entity, EntityInterface $existent = null)
 {
     if (0 === $entity->getSkus()->count()) {
         throw new InvalidArgumentException('Product precisa conter SKU!');
     }
     try {
         $status = $entity->get('status');
         if (!$status instanceof Status) {
             $status = $this->fetchStatusById($entity->getId());
         }
         if (true === $status->isPending()) {
             return ['pending' => true];
         }
     } catch (RuntimeException $e) {
         if (404 === $e->getCode()) {
             return $this->resolveNew($entity);
         }
     }
     $response = [];
     if (true === $this->strategy['info']) {
         $compare = $this->attributesDiff($entity, $existent, ['department', 'productType']);
         $response['patch'] = $this->patch($entity, $compare);
     }
     $response['skus'] = [];
     foreach ($entity->getSkus() as $sku) {
         $previous = null;
         if ($existent instanceof EntityInterface) {
             $previous = $existent->getSkus()->findById($sku->getId());
         }
         $response['skus'][] = $this->skuManager()->update($sku, $previous);
     }
     return $response;
 }
示例#2
0
 public function save(EntityInterface $entity, $route = 'save')
 {
     $existent = $entity->getPrevious();
     if ($existent) {
         return $this->update($entity, $existent);
     }
     return $this->execute($this->factoryMap($route), $entity->toJson($route));
 }
示例#3
0
 public function save(EntityInterface $product, $route = 'save')
 {
     $existent = $product->getPrevious();
     $this->log('INFO', 'save', ['route' => $route, 'existent' => $existent]);
     if ($existent) {
         return $this->update($product, $existent);
     }
     return $this->getPool()->add($product);
 }
示例#4
0
 public function update(EntityInterface $entity, EntityInterface $existent)
 {
     if ($this->atributesDiff($existent->getPrice(), $entity->getPrice(), ['listPrice', 'sellPrice'])) {
         $this->savePrice($entity);
     }
     if ($this->atributesDiff($existent, $entity, ['stockQuantity'])) {
         $this->saveStock($entity);
     }
     return true;
 }
示例#5
0
 public function update(EntityInterface $entity, EntityInterface $existent)
 {
     foreach ($entity->getSku() as $sku) {
         if (!$existent->has($sku)) {
             $this->addSku($entity, $sku);
         } else {
             $this->updateSku($sku);
         }
     }
     return true;
 }
示例#6
0
 protected function attributesResolv(EntityInterface $entityA, array $attributes = null)
 {
     if (empty($attributes)) {
         $list = [];
         foreach ($entityA->getSchema() as $key => $value) {
             if ($value !== 'object') {
                 $list[] = $key;
             }
         }
         return $list;
     }
     return $attributes;
 }
示例#7
0
 /**
  * @testdox Possui método ``getAmountInt()`` para acessar e definir Amount em formato "minor units"
  * @dataProvider dataProviderObject
  * @test
  */
 public function getterAmountInt(EntityInterface $object)
 {
     foreach ([128, 129.01, 88.09999999999999, 457883.99] as $num) {
         $object->setAmount($num);
         $out = $object->getAmountInt();
         $this->assertSame((double) $num * 100, (double) $out);
     }
 }
示例#8
0
 /**
  * @testdox Possui método ``setSocialSecurityNumber()`` que define SocialSecurityNumber
  * @dataProvider dataProviderObject
  * @test
  */
 public function setterSocialSecurityNumber(EntityInterface $object)
 {
     $object->setSocialSecurityNumber('12345678911');
     $this->assertSame('12345678911', $object->getSocialSecurityNumber());
 }
示例#9
0
 public function save(EntityInterface $entity, $route = 'save')
 {
     return $this->execute($this->factoryMap($route), $entity->toJson($route));
 }
示例#10
0
 public function hydrate(EntityInterface $sku)
 {
     $sku->setPrice($this->getDetail($sku, 'Price'))->setStock($this->getDetail($sku, 'Stock'))->setStatus($this->getDetail($sku, 'Status'));
     return $this->hydratePriceSchedule($sku);
 }