protected function getPriceScheduleCollection(EntityInterface $sku) { try { $response = $this->perform($this->factoryMap('getPriceSchedule', ['sku' => $sku->getId()])); $data = $this->processResponse($response); if (empty($data)) { throw new ManagerException('No price schedule on SKU #' . $sku->getId()); } } catch (ManagerException $e) { $this->log('error', $e->getMessage()); return; } $collection = new PriceScheduleCollection($data->toArray()); return $collection; }
/** * {@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; }