Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * @param array $data
  * @return Struct\Media
  */
 public function hydrate(array $data)
 {
     $media = new Struct\Media();
     if (isset($data['__media_id'])) {
         $media->setId((int) $data['__media_id']);
     }
     if (isset($data['__media_name'])) {
         $media->setName($data['__media_name']);
     }
     if (isset($data['__media_description'])) {
         $media->setDescription($data['__media_description']);
     }
     if (isset($data['__media_type'])) {
         $media->setType($data['__media_type']);
     }
     if (isset($data['__media_extension'])) {
         $media->setExtension($data['__media_extension']);
     }
     if (isset($data['__media_path'])) {
         $media->setFile($this->mediaService->getUrl($data['__media_path']));
     }
     /**
      * Live Migration to add width/height to images
      */
     if ($media->getType() == Struct\Media::TYPE_IMAGE && $this->mediaService->has($data['__media_path'])) {
         if (array_key_exists('__media_width', $data) && array_key_exists('__media_height', $data)) {
             if ($data['__media_width'] === null || $data['__media_height'] === null) {
                 list($width, $height) = getimagesizefromstring($this->mediaService->read($data['__media_path']));
                 $this->database->executeUpdate('UPDATE s_media SET width = :width, height = :height WHERE id = :id', [':width' => $width, ':height' => $height, ':id' => $data['__media_id']]);
                 $data['__media_width'] = $width;
                 $data['__media_height'] = $height;
             }
         }
     }
     if (isset($data['__media_width'])) {
         $media->setWidth((int) $data['__media_width']);
     }
     if (isset($data['__media_height'])) {
         $media->setHeight((int) $data['__media_height']);
     }
     if ($media->getType() == Struct\Media::TYPE_IMAGE && $data['__mediaSettings_create_thumbnails']) {
         $media->setThumbnails($this->getMediaThumbnails($data));
     }
     if (!empty($data['__mediaAttribute_id'])) {
         $attribute = $this->attributeHydrator->hydrate($this->extractFields('__mediaAttribute_', $data));
         $media->addAttribute('media', $attribute);
     }
     return $media;
 }
Ejemplo n.º 3
0
 /**
  * @param array $data Contains the array data for the media
  * @return array
  */
 private function getMediaThumbnails(array $data)
 {
     $thumbnailData = $this->thumbnailManager->getMediaThumbnails($data['__media_name'], $data['__media_type'], $data['__media_extension'], explode(';', $data['__mediaSettings_thumbnail_size']));
     $thumbnails = [];
     foreach ($thumbnailData as $row) {
         $retina = $row['retinaSource'];
         if (!$data['__mediaSettings_thumbnail_high_dpi']) {
             $retina = null;
         }
         if (!empty($retina)) {
             $retina = $this->mediaService->getUrl($retina);
         }
         $thumbnails[] = new Struct\Thumbnail($this->mediaService->getUrl($row['source']), $retina, $row['maxWidth'], $row['maxHeight']);
     }
     return $thumbnails;
 }
 /**
  * Returns article images
  *
  * @param array $ids
  * @param array $columns
  * @return array
  * @throws
  */
 public function read($ids, $columns)
 {
     if (!$ids && empty($ids)) {
         $message = SnippetsHelper::getNamespace()->get('adapters/articlesImages/no_article_images_ids', 'Can not read article images without ids.');
         throw new \Exception($message);
     }
     if (!$columns && empty($columns)) {
         $message = SnippetsHelper::getNamespace()->get('adapters/articlesImages/no_article_images_column', 'Can not read article images without column names.');
         throw new \Exception($message);
     }
     $builder = $this->getBuilder($columns, $ids);
     $result['default'] = $builder->getQuery()->getArrayResult();
     foreach ($result['default'] as &$image) {
         $image['image'] = $this->mediaService->getUrl($image['image']);
         if (empty($image['relations'])) {
             continue;
         }
         $relations = explode(';', $image['relations']);
         $relations = array_unique($relations);
         $out = [];
         foreach ($relations as $rule) {
             $split = explode('|', $rule);
             $ruleId = $split[0];
             $name = $split[2];
             $groupName = $split[3];
             if ($groupName && $name) {
                 $out[$ruleId][] = "{$groupName}:{$name}";
             }
         }
         $temp = [];
         foreach ($out as $group) {
             $temp[] = "{" . implode('|', $group) . "}";
         }
         $image['relations'] = implode('&', $temp);
     }
     return $result;
 }