/** * Parse offers (if any are provided). * * @param OffersResponse $offersResponse * @param array $body */ protected function parseOffers(OffersResponse $offersResponse, array $body) { $offers = $body['offers']; $factory = new OfferFactory(); foreach (OfferType::getValues() as $type) { foreach (OfferCondition::getValues() as $condition) { $key = vsprintf('%s%s', [$type, ucfirst($condition)]); if (!Arr::has($offers, $key)) { continue; } foreach ($offers[$key] as $offer) { $offersResponse->addOffer($type, $condition, $factory->makeFromArray($offer)); } } } }
/** * Add a offer to the response. * * @param string $type * @param string $condition * @param Offer $offer * * @throws InvalidArgumentException */ public function addOffer($type, $condition, Offer $offer) { Arguments::contain(Boa::in(OfferType::getValues()), Boa::in(OfferCondition::getValues()), Boa::instance(Offer::class))->check($type, $condition, $offer); if ($type === OfferType::TYPE_FBA) { if ($condition === OfferCondition::CONDITION_NEW) { $this->fbaNewOffers[] = $offer; } elseif ($condition === OfferCondition::CONDITION_USED) { $this->fbaUsedOffers[] = $offer; } } elseif ($type === OfferType::TYPE_MERCHANT_FULFILLED) { if ($condition === OfferCondition::CONDITION_NEW) { $this->merchantNewOffers[] = $offer; } elseif ($condition === OfferCondition::CONDITION_USED) { $this->merchantUsedOffers[] = $offer; } } }