/** * @param \DOMDocument $dom * @param \DOMElement $productNode * @param Product $product */ protected function addCommonNodesToContentDom($dom, \DOMElement $productNode, Product $product) { $productIdNode = $dom->createElement("id", $product->getProductId()); $productNode->appendChild($productIdNode); $storeIdNode = $dom->createElement("storeid", $product->getStoreId()); $productNode->appendChild($storeIdNode); $languageNode = $dom->createElement("language", $product->getLanguage()); $productNode->appendChild($languageNode); $availabilityNode = $dom->createElement("availability", $product->getAvailability() ? 1 : 0); $productNode->appendChild($availabilityNode); $skuNode = $dom->createElement("sku", $product->getSku()); $productNode->appendChild($skuNode); $titleNode = $dom->createElement("title"); $titleValueTextNode = $dom->createTextNode($product->getTitle()); $titleNode->appendChild($titleValueTextNode); $productNode->appendChild($titleNode); $descriptionNode = $dom->createElement("description"); $descriptionValueTextNode = $dom->createTextNode($product->getDescription()); $descriptionNode->appendChild($descriptionValueTextNode); $productNode->appendChild($descriptionNode); $shortDescriptionNode = $dom->createElement("short_description"); $shortDescriptionValueTextNode = $dom->createTextNode($product->getShortDescription()); $shortDescriptionNode->appendChild($shortDescriptionValueTextNode); $productNode->appendChild($shortDescriptionNode); $priceNode = $dom->createElement("price", number_format($product->getPrice(), 2)); $productNode->appendChild($priceNode); $specialPriceNode = $dom->createElement("special_price", number_format($product->getSpecialPrice(), 2)); $productNode->appendChild($specialPriceNode); $groupPriceNode = $dom->createElement("group_price", number_format($product->getGroupPrice(), 2)); $productNode->appendChild($groupPriceNode); $imageLink = $dom->createElement("image_link", $product->getImageLink()); $productNode->appendChild($imageLink); }
/** * @test */ public function canInitializeProductFromProductXml() { $expectedXml = $this->getFixtureContent('Api/Client/Domain/Document/Fixture/testproduct.xml'); $this->product->__setProperty('content', $expectedXml); $this->product->afterReconstitution(); $this->assertSame(118948, $this->product->getProductId(), 'Could not get product with expected productId'); $this->assertSame(1, $this->product->getStoreId(), 'Could not restore storeId'); $this->assertSame("de_DE", $this->product->getLanguage(), 'Could not restore language'); $this->assertSame("103115", $this->product->getSku(), 'Could not restore sku'); $this->assertSame("Foo", $this->product->getTitle(), 'Could not restore title'); $this->assertSame("long description", $this->product->getDescription(), 'Could not restore description'); $this->assertSame("short description", $this->product->getShortDescription(), 'Could not restore short description'); $this->assertSame(42.36, $this->product->getPrice(), 'Could not restore price'); $this->assertSame(100.0, $this->product->getSpecialPrice(), 'Could not get special price'); $this->assertSame(101.0, $this->product->getGroupPrice(), 'Could not get group price'); $this->assertSame('http://www.searchperience.de/test.gif', $this->product->getImageLink(), 'Could not restore image link'); $this->assertSame(2, count($this->product->getCategoryPaths()), 'Could not restore category pathes'); $this->assertSame(2, count($this->product->getAttributes()), 'Could not restore attributes'); }