/** * @param \DOMXPath $xpath * @param Product $product */ protected function restoreAttributesFromDOMContent($xpath, Product $product) { $attributeNodes = $xpath->query("//attribute"); $attributes = array(); foreach ($attributeNodes as $attributeNode) { /** @var $attributeNode \DOMElement */ $name = $attributeNode->getAttribute("name"); $type = $attributeNode->getAttribute("type"); $forSearching = $attributeNode->getAttribute("forsearching") == "1"; $forFaceting = $attributeNode->getAttribute("forfaceting") == "1"; $forSorting = $attributeNode->getAttribute("forsorting") == "1"; $attribute = new ProductAttribute(); $attribute->setName($name); $attribute->setType($type); $attribute->setForSearching($forSearching); $attribute->setForFaceting($forFaceting); $attribute->setForSorting($forSorting); $values = $xpath->query("value", $attributeNode); foreach ($values as $value) { /** @var $value \DOMElement */ $attribute->addValue($value->textContent); } $attributes[$attribute->getName()] = $attribute; } $product->__setProperty('attributes', $attributes); }
/** * @test */ public function canGetAttributeByName() { $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); $this->assertEquals($attribute2, $this->product->getAttributeByName("defaults")); }