/** * @param ListProduct $listProduct * @return Product */ public static function createFromListProduct(ListProduct $listProduct) { $product = new self($listProduct->getId(), $listProduct->getVariantId(), $listProduct->getNumber()); foreach ($listProduct as $key => $value) { $product->{$key} = $value; } return $product; }
/** * Internal function which converts only the data of a list product. * Associated data won't converted. * * @param StoreFrontBundle\Struct\ListProduct $product * @return array */ private function getListProductData(StoreFrontBundle\Struct\ListProduct $product) { $createDate = null; if ($product->getCreatedAt()) { $createDate = $product->getCreatedAt()->format('Y-m-d'); } $data = array('articleID' => $product->getId(), 'articleDetailsID' => $product->getVariantId(), 'ordernumber' => $product->getNumber(), 'highlight' => $product->highlight(), 'description' => $product->getShortDescription(), 'description_long' => $product->getLongDescription(), 'esd' => $product->hasEsd(), 'articleName' => $product->getName(), 'taxID' => $product->getTax()->getId(), 'tax' => $product->getTax()->getTax(), 'instock' => $product->getStock(), 'isAvailable' => $product->isAvailable(), 'weight' => $product->getWeight(), 'shippingtime' => $product->getShippingTime(), 'pricegroupActive' => false, 'pricegroupID' => null, 'length' => $product->getLength(), 'height' => $product->getHeight(), 'width' => $product->getWidth(), 'laststock' => $product->isCloseouts(), 'additionaltext' => $product->getAdditional(), 'datum' => $createDate, 'sales' => $product->getSales(), 'filtergroupID' => null, 'priceStartingFrom' => null, 'pseudopricePercent' => null, 'sVariantArticle' => null, 'sConfigurator' => $product->hasConfigurator(), 'metaTitle' => $product->getMetaTitle(), 'shippingfree' => $product->isShippingFree(), 'suppliernumber' => $product->getManufacturerNumber(), 'notification' => $product->allowsNotification(), 'ean' => $product->getEan(), 'keywords' => $product->getKeywords(), 'sReleasedate' => $this->dateToString($product->getReleaseDate()), 'template' => $product->getTemplate()); if ($product->hasAttribute('core')) { $attributes = $product->getAttribute('core')->toArray(); unset($attributes['id'], $attributes['articleID'], $attributes['articledetailsID']); $data = array_merge($data, $attributes); } $data['attributes'] = $product->getAttributes(); if ($product->getManufacturer()) { $manufacturer = array('supplierName' => $product->getManufacturer()->getName(), 'supplierImg' => $product->getManufacturer()->getCoverFile(), 'supplierID' => $product->getManufacturer()->getId(), 'supplierDescription' => $product->getManufacturer()->getDescription()); if (!empty($manufacturer['supplierImg'])) { $manufacturer['supplierImg'] = $this->mediaService->getUrl($manufacturer['supplierImg']); } $data = array_merge($data, $manufacturer); $data['supplier_attributes'] = $product->getManufacturer()->getAttributes(); } if ($product->hasAttribute('marketing')) { /**@var $marketing StoreFrontBundle\Struct\Product\MarketingAttribute */ $marketing = $product->getAttribute('marketing'); $data['newArticle'] = $marketing->isNew(); $data['sUpcoming'] = $marketing->comingSoon(); $data['topseller'] = $marketing->isTopSeller(); } $today = new \DateTime(); if ($product->getReleaseDate() && $product->getReleaseDate() > $today) { $data['sReleasedate'] = $product->getReleaseDate()->format('Y-m-d'); } return $data; }
/** * Creates different links for the product like `add to basket`, `add to note`, `view detail page`, ... * * @param StoreFrontBundle\Struct\ListProduct $product * @param null $categoryId * @return array */ private function getLinksOfProduct(StoreFrontBundle\Struct\ListProduct $product, $categoryId = null) { $baseFile = $this->config->get('baseFile'); $context = $this->contextService->getShopContext(); $detail = $baseFile . "?sViewport=detail&sArticle=" . $product->getId(); if ($categoryId) { $detail .= '&sCategory=' . $categoryId; } $rewrite = Shopware()->Modules()->Core()->sRewriteLink($detail, $product->getName()); $basket = $baseFile . "?sViewport=basket&sAdd=" . $product->getNumber(); $note = $baseFile . "?sViewport=note&sAdd=" . $product->getNumber(); $friend = $baseFile . "?sViewport=tellafriend&sDetails=" . $product->getId(); $pdf = $baseFile . "?sViewport=detail&sDetails=" . $product->getId() . "&sLanguage=" . $context->getShop()->getId() . "&sPDF=1"; return array('linkBasket' => $basket, 'linkDetails' => $detail, 'linkDetailsRewrited' => $rewrite, 'linkNote' => $note, 'linkTellAFriend' => $friend, 'linkPDF' => $pdf); }