/** * @param array $drupalProduct * @param ProductValue $productValue * @param string $field * @param array $context * @throws \Pim\Bundle\CatalogBundle\Exception\MissingIdentifierException */ public function normalize(array &$drupalProduct, $productValue, $field, array $context = array()) { $media = $productValue->getMedia(); if ($media && null !== $media->getFilename()) { $drupalProduct['values'][$field][$context['locale']][] = ['type' => 'pim_catalog_image', 'filename_original' => $media->getOriginalFilename(), 'filename' => $media->getFilename(), 'mimetype' => $media->getMimeType(), 'length' => filesize($this->mediaManager->getFilePath($media)), 'absolute_path' => $this->mediaManager->getFilePath($media), 'attribute_id' => $media->getValue()->getAttribute()->getId(), 'media_id' => $media->getId(), 'rest_url' => '/api/rest/media/' . $productValue->getEntity()->getIdentifier() . '/' . $productValue->getAttribute()->getId()]; } }
/** * @param array $drupalProduct * @param ProductValue $productValue * @param string $field * @param array $context */ public function normalize(array &$drupalProduct, $productValue, $field, array $context = array()) { $text = $productValue->getText(); $attribute = $productValue->getAttribute(); if (null !== $text) { $drupalProduct['values'][$field][$context['locale']][] = array('type' => 'pim_catalog_textarea', 'value' => $text); } }
function let(ProductValue $value, MappingCollection $attributeMapping, AbstractAttribute $attribute) { $this->globalContext = ['identifier' => 'identifier', 'scopeCode' => 'scope_code', 'localeCode' => 'locale_code', 'onlyLocalized' => false, 'magentoAttributes' => ['attribute_code' => ['code' => 'attribute_ode', 'scope' => 'global']], 'magentoAttributesOptions' => [], 'currencyCode' => 'currency_code', 'attributeCodeMapping' => $attributeMapping]; $attributeMapping->getTarget('attribute_code')->willReturn('attribute_code'); $value->getData()->willReturn('hello'); $value->getAttribute()->willReturn($attribute); $value->getScope()->willReturn('scope_code'); $attribute->getCode()->willReturn('attribute_code'); }
/** * @param ProductValue $productValue * @param $attribute * @return string */ public function getSerializedData(ProductValue $productValue, $attribute) { /** @var ProductMedia $media */ $media = $productValue->getMedia(); /** @var MediaManager $mediaManager */ $mediaManager = $this->get('pim_catalog.manager.media'); /** @var ProductValue $productValue */ $info_media = new \stdClass(); $info_media->content = $mediaManager->getBase64($media); $info_media->created = $productValue->getAttribute()->getCreated()->getTimestamp(); $info_media->updated = $productValue->getAttribute()->getUpdated()->getTimestamp(); $info_media->filename = $media->getFilename(); $info_media->filepath = $media->getFilePath(); $info_media->originalFilename = $media->getOriginalFilename(); $info_media->mimeType = $media->getMimeType(); $info_media->size = filesize($media->getFilePath()); $data = json_encode($info_media); return $data; }
/** * {@inheritDoc} */ public function getAttribute() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getAttribute', array()); return parent::getAttribute(); }