/** * @param \stdObject $jsonObject * @param ModelFactoryInterface $factory * * @return $this */ public function parseJson($jsonObject, ModelFactoryInterface $factory) { $this->categories = array(); $this->parentChildIds = array(); if (isset($jsonObject->parent_child)) { // this hack converts the array keys to integers, otherwise $this->parentChildIds[$id] fails $this->parentChildIds = json_decode(json_encode($jsonObject->parent_child), true); foreach ($jsonObject->ids as $id => $jsonCategory) { $this->categories[$id] = $factory->createCategory($jsonCategory, $this); } } $this->cacheCategories(); return $this; }
/** * @param \stdClass $jsonObject * @param ModelFactoryInterface $factory * * @return static */ public static function createFromJson(\stdClass $jsonObject, ModelFactoryInterface $factory) { $productsEansResult = new static(); $productsEansResult->pageHash = isset($jsonObject->pageHash) ? $jsonObject->pageHash : null; if (isset($jsonObject->eans)) { foreach ($jsonObject->eans as $jsonProduct) { if (isset($jsonProduct->error_code)) { $productsEansResult->errors[] = $jsonProduct; $productsEansResult->eansNotFound = array_merge($productsEansResult->eansNotFound, $jsonProduct->ean); continue; } $productsEansResult->products[] = $factory->createProduct($jsonProduct); } } return $productsEansResult; }
protected function parseFacets($jsonObject, ModelFactoryInterface $factory) { if (isset($jsonObject->categories)) { $this->categories = $factory->createCategoriesFacets($jsonObject->categories); unset($jsonObject->categories); } if (isset($jsonObject->prices)) { $this->priceRanges = $factory->createPriceRanges($jsonObject->prices); unset($jsonObject->prices); } if (isset($jsonObject->sale)) { $this->saleCounts = $factory->createSaleFacet($jsonObject->sale); unset($jsonObject->sale); } if (isset($jsonObject->new_in_since_date)) { $this->newInCounts = $factory->createNewInFacets($jsonObject->new_in_since_date); unset($jsonObject->new_in_since_date); } if (isset($jsonObject->product_facets)) { $this->productFacets = $factory->createProductFacets($jsonObject->product_facets); unset($jsonObject->product_facets); } $this->facets = $factory->createFacetsCounts($jsonObject); unset($jsonObject->facets); }
/** * returns an array of materials, each material has a name and optional a type and compositions * The name is e.g. "Obermaterial", "Futter 1" or "Füllung" * The type could be "shell" or "lining" * * The Materials are lazy parsed * * @return Material[]|null */ public function getMaterials() { if ($this->materials === null && isset($this->jsonObject->materials)) { $this->materials = $this->factory->createMaterialList($this->jsonObject->materials); } return $this->materials; }
/** * @param \stdClass $jsonObject * @param ModelFactoryInterface $factory * * @return static */ public static function createFromJson(\stdClass $jsonObject, ModelFactoryInterface $factory) { $productsResult = new static(); $productsResult->pageHash = isset($jsonObject->pageHash) ? $jsonObject->pageHash : null; if (isset($jsonObject->ids)) { foreach ($jsonObject->ids as $key => $jsonProduct) { if (isset($jsonProduct->error_code)) { $productsResult->idsNotFound[] = $key; $productsResult->errors[] = $jsonProduct; continue; } $productsResult->products[$key] = $factory->createProduct($jsonProduct); } } return $productsResult; }
public function requireFacets($fetchForced = false) { if (!($fetchForced || $this->factory->getFacetManager()->isEmpty())) { return $this; } $this->ghostQuery[self::QUERY_FACETS] = array('facets' => new \stdClass()); return $this; }
/** * @return \AboutYou\SDK\Model\CategoryManager\CategoryManagerInterface */ private function getCategoryManager() { return $this->factory->getCategoryManager(); }
/** * parse autocompleted brands. * * @param \stdClass $jsonObject * @param ModelFactoryInterface $factory * * @return Brand[] */ protected static function parseBrands(\stdClass $jsonObject, ModelFactoryInterface $factory) { if (!property_exists($jsonObject, 'brands')) { return self::NOT_REQUESTED; } if ($jsonObject->brands === null) { return array(); } $brands = array(); foreach ($jsonObject->brands as $brand) { $brands[] = $factory->createBrand($brand); } return $brands; }
protected function parseItems($jsonObject, ModelFactoryInterface $factory) { $products = array(); if (!empty($jsonObject->products)) { foreach ($jsonObject->products as $productId => $jsonProduct) { $products[$productId] = $factory->createProduct($jsonProduct); } } $this->products = $products; $vids = array(); if (!empty($jsonObject->order_lines)) { foreach ($jsonObject->order_lines as $index => $jsonItem) { if (isset($jsonItem->set_items)) { $item = $factory->createBasketSet($jsonItem, $products); } else { $vids[] = $jsonItem->variant_id; $item = $factory->createBasketItem($jsonItem, $products); } if ($item->hasErrors()) { $this->errors[$index] = $item; } else { $this->items[$item->getId()] = $item; } } } $vids = array_values(array_unique($vids)); $this->uniqueVariantCount = count($vids); }
/** * @param \stdClass $jsonObject * @param ModelFactoryInterface $factory * @param Product[] $products * * @return WishListSet */ public static function createFromJson(\stdClass $jsonObject, ModelFactoryInterface $factory, $products) { $set = new static($jsonObject->id, isset($jsonObject->additional_data) ? (array) $jsonObject->additional_data : null, isset($jsonObject->added_on) ? $jsonObject->added_on : null); $set->parseErrorResult($jsonObject); foreach ($jsonObject->set_items as $index => $jsonItem) { $item = $factory->createWishListSetItem($jsonItem, $products); if ($item->hasErrors()) { $set->errors[$index] = $item; } else { $set->items[$index] = $item; } } $set->totalPrice = isset($jsonObject->total_price) ? $jsonObject->total_price : null; $set->totalNet = isset($jsonObject->total_net) ? $jsonObject->total_net : null; $set->totalVat = isset($jsonObject->total_vat) ? $jsonObject->total_vat : null; return $set; }
/** * @param ModelFactoryInterface $modelFactory */ public function setResultFactory(ModelFactoryInterface $modelFactory) { $this->modelFactory = $modelFactory; $modelFactory->setBaseImageUrl($this->baseImageUrl); }