/** * @param array $data * @return Struct\Category */ public function hydrate(array $data) { $category = new Struct\Category(); $this->assignCategoryData($category, $data); if ($data['__media_id']) { $category->setMedia($this->mediaHydrator->hydrate($data)); } if ($data['__categoryAttribute_id']) { $attribute = $this->extractFields('__categoryAttribute_', $data); $category->addAttribute('core', $this->attributeHydrator->hydrate($attribute)); } return $category; }
/** * @param array $data * @return \Shopware\Bundle\StoreFrontBundle\Struct\Product\Link */ public function hydrate(array $data) { $link = new Struct\Product\Link(); $link->setId((int) $data['__link_id']); $link->setDescription($data['__link_description']); $link->setLink($data['__link_link']); $link->setTarget($data['__link_target']); if (!empty($data['__linkAttribute_id'])) { $attribute = $this->extractFields('__linkAttribute_', $data); $link->addAttribute('core', $this->attributeHydrator->hydrate($attribute)); } return $link; }
/** * Creates a new Struct\Product\Download struct with the passed data. * * @param array $data * @return \Shopware\Bundle\StoreFrontBundle\Struct\Product\Download */ public function hydrate(array $data) { $download = new Struct\Product\Download(); $download->setId((int) $data['__download_id']); $download->setDescription($data['__download_description']); $download->setFile($data['__download_filename']); $download->setSize((double) $data['__download_size']); if (!empty($data['__downloadAttribute_id'])) { $attribute = $this->extractFields('__downloadAttribute_', $data); $download->addAttribute('core', $this->attributeHydrator->hydrate($attribute)); } return $download; }
/** * @param array $data * @return Struct\Customer\Group */ public function hydrate(array $data) { $customerGroup = new Struct\Customer\Group(); $customerGroup->setId((int) $data['__customerGroup_id']); $customerGroup->setName($data['__customerGroup_description']); $customerGroup->setDisplayGrossPrices((bool) $data['__customerGroup_tax']); $customerGroup->setKey($data['__customerGroup_groupkey']); $customerGroup->setMinimumOrderValue((double) $data['__customerGroup_minimumorder']); $customerGroup->setPercentageDiscount((double) $data['__customerGroup_discount']); $customerGroup->setSurcharge((double) $data['__customerGroup_minimumordersurcharge']); $customerGroup->setUseDiscount((bool) $data['__customerGroup_mode']); if (!empty($data['__customerGroupAttribute_id'])) { $attribute = $this->attributeHydrator->hydrate($this->extractFields('__customerGroupAttribute_', $data)); $customerGroup->addAttribute('core', $attribute); } return $customerGroup; }
/** * @param array $data * @return \Shopware\Bundle\StoreFrontBundle\Struct\Product\PriceRule */ public function hydratePriceRule(array $data) { $price = new Struct\Product\PriceRule(); $price->setId((int) $data['__price_id']); $price->setFrom((int) $data['__price_from']); $price->setPrice((double) $data['__price_price']); $price->setPseudoPrice((double) $data['__price_pseudoprice']); if (strtolower($data['__price_to']) == 'beliebig') { $price->setTo(null); } else { $price->setTo((int) $data['__price_to']); } if (isset($data['__price___attribute_id'])) { $attribute = $this->attributeHydrator->hydrate($this->extractFields('__attribute_', $data)); $price->addAttribute('core', $attribute); } return $price; }
/** * Iterates the attribute data and assigns the attribute struct to the product. * * @param Struct\ListProduct $product * @param $data */ private function assignAttributeData(Struct\ListProduct $product, $data) { $translation = $this->getProductTranslation($data); $attribute = $this->attributeHydrator->hydrate($this->extractFields('__productAttribute_', $data)); foreach ($translation as $key => $value) { if ($attribute->exists($key)) { $attribute->set($key, $value); } } $product->addAttribute('core', $attribute); }
/** * @param array $data * @return \Shopware\Bundle\StoreFrontBundle\Struct\Media */ public function hydrateProductImage(array $data) { $media = $this->hydrate($data); $data = array_merge($data, $this->getImageTranslation($data)); $media->setName($data['__image_description']); $media->setPreview((bool) ($data['__image_main'] == 1)); if (!empty($data['__imageAttribute_id'])) { $attribute = $this->attributeHydrator->hydrate($this->extractFields('__imageAttribute_', $data)); $media->addAttribute('image', $attribute); } return $media; }
/** * @param QueryBuilder $query * @return array */ private function getProducts(QueryBuilder $query) { /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */ $statement = $query->execute(); $data = $statement->fetchAll(\PDO::FETCH_ASSOC); $products = []; foreach ($data as $row) { $product = new BaseProduct((int) $row['__product_id'], (int) $row['__variant_id'], $row['__variant_ordernumber']); $product->addAttribute('search', $this->attributeHydrator->hydrate($row)); $products[$product->getNumber()] = $product; } return $products; }
/** * @param array $data * @return Struct\Property\Set */ private function hydrateSet(array $data) { $set = new Struct\Property\Set(); $translation = $this->getTranslation($data, '__propertySet_translation', '__propertySet_translation_fallback', ['groupName' => '__propertySet_name']); $data = array_merge($data, $translation); $set->setId((int) $data['__propertySet_id']); $set->setName($data['__propertySet_name']); $set->setComparable((bool) $data['__propertySet_comparable']); if ($data['__propertySetAttribute_id']) { $attribute = $this->extractFields('__propertySetAttribute_', $data); $set->addAttribute('core', $this->attributeHydrator->hydrate($attribute)); } return $set; }
/** * @param array $data * @return \Shopware\Bundle\StoreFrontBundle\Struct\Country\State */ public function hydrateState(array $data) { $state = new Struct\Country\State(); $translation = $this->getTranslation($data, '__countryState_translation', '__countryState_translation_fallback', $data['__countryState_id'], $this->translationStateFields); $data = array_merge($data, $translation); $state->setId((int) $data['__countryState_id']); if (isset($data['__countryState_name'])) { $state->setName($data['__countryState_name']); } if (isset($data['__countryState_shortcode'])) { $state->setCode($data['__countryState_shortcode']); } if ($data['__countryStateAttribute_id'] !== null) { $attribute = $this->attributeHydrator->hydrate($this->extractFields('__countryStateAttribute_', $data)); $state->addAttribute('core', $attribute); } return $state; }
/** * @param Struct\Product\Manufacturer $manufacturer * @param array $data */ private function assignAttribute(Struct\Product\Manufacturer $manufacturer, array $data) { $attribute = $this->attributeHydrator->hydrate($this->extractFields('__manufacturerAttribute_', $data)); $manufacturer->addAttribute('core', $attribute); }