/** * {@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; }
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)); }
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); }
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; }
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; }
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; }
/** * @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); } }
/** * @testdox Possui método ``setSocialSecurityNumber()`` que define SocialSecurityNumber * @dataProvider dataProviderObject * @test */ public function setterSocialSecurityNumber(EntityInterface $object) { $object->setSocialSecurityNumber('12345678911'); $this->assertSame('12345678911', $object->getSocialSecurityNumber()); }
public function save(EntityInterface $entity, $route = 'save') { return $this->execute($this->factoryMap($route), $entity->toJson($route)); }
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); }