/** * @param \DOMXPath $xpath * @param Product $product */ protected function restoreCategoryPathsFromDOMContent($xpath, Product $product) { $categoryPaths = array(); $categoryPathNodes = $xpath->query("//category_path"); foreach ($categoryPathNodes as $categoryPathNode) { /** @var $node \DOMElement */ $productCategoryPath = new ProductCategoryPath(); $productCategoryPath->setCategoryPath((string) $categoryPathNode->textContent); for ($i = 0; $i < 5; $i++) { if (!isset($categoryPathNode->nextSibling)) { break; } $categoryPathNode = $categoryPathNode->nextSibling; if ($categoryPathNode->nodeName == 'category_id') { $productCategoryPath->setCategoryId((int) $categoryPathNode->textContent); break; } } $categoryPaths[$productCategoryPath->getCategoryId()] = $productCategoryPath; } $product->__setProperty('categoryPaths', $categoryPaths); }
/** * @test */ public function canGetSameDocumentAsFromFixture() { $expectedXml = $this->getFixtureContent('Api/Client/Domain/Document/Fixture/testproduct.xml'); $this->product->setProductId(118948); $this->product->setStoreId(1); $this->product->setLanguage("de_DE"); $this->product->setAvailability(true); $this->product->setSku(103115); $this->product->setTitle("Foo"); $this->product->setDescription("long description"); $this->product->setShortDescription("short description"); $this->product->setPrice(42.36); $this->product->setSpecialPrice(100); $this->product->setGroupPrice(101); $this->product->setImageLink('http://www.searchperience.de/test.gif'); $categoryPath1 = new ProductCategoryPath(); $categoryPath1->setCategoryId(7); $categoryPath1->setCategoryPath("Moda & Accessori"); $this->product->addCategoryPath($categoryPath1); $categoryPath2 = new ProductCategoryPath(); $categoryPath2->setCategoryId(36); $categoryPath2->setCategoryPath("Moda & Accessori/Abbigliamento"); $this->product->addCategoryPath($categoryPath2); $attribute1 = new ProductAttribute(); $attribute1->setName('color'); $attribute1->setType(ProductAttribute::TYPE_TEXT); $attribute1->setForFaceting(true); $attribute1->setForSorting(true); $attribute1->setForSearching(true); $attribute1->addValue("red"); $this->product->addAttribute($attribute1); $attribute2 = new ProductAttribute(); $attribute2->setName('defaults'); $attribute2->setType(ProductAttribute::TYPE_STRING); $attribute2->addValue("i like searchperience"); $attribute2->addValue("foobar"); $this->product->addAttribute($attribute2); $generatedXml = $this->product->getContent(); $this->assertXmlStringEqualsXmlString($expectedXml, $generatedXml, 'Method getContent on product did not produce expected result'); }