/**
  * @param ProductManager   $manager    the product manager
  * @param ProductInterface $product    the entity
  * @param array            $attributes the attributes
  */
 protected function addValues(ProductManager $manager, ProductInterface $product, $attributes)
 {
     foreach ($attributes as $attribute) {
         $value = $manager->createProductValue();
         $value->setAttribute($attribute);
         $product->addValue($value);
     }
 }
 /**
  * @param ProductManager   $manager    the product manager
  * @param ProductInterface $product    the entity
  * @param array            $attributes the attributes
  */
 protected function addValues(ProductManager $manager, ProductInterface $product, $attributes)
 {
     foreach ($attributes as $attribute) {
         $value = $manager->createProductValue();
         $value->setAttribute($attribute);
         if ($attribute->getDefaultValue() !== null) {
             $value->setData($attribute->getDefaultValue());
         }
         $product->addValue($value);
     }
 }
 /**
  * Returns a ProductValue
  *
  * @param ProductInterface    $product
  * @param ColumnInfoInterface $columnInfo
  *
  * @return ProductValueInterface
  */
 protected function getProductValue(ProductInterface $product, ColumnInfoInterface $columnInfo)
 {
     $productValue = $product->getValue($columnInfo->getName(), $columnInfo->getLocale(), $columnInfo->getScope());
     if (null === $productValue) {
         $productValue = $this->productManager->createProductValue();
         $productValue->setAttribute($columnInfo->getAttribute());
         $productValue->setLocale($columnInfo->getLocale());
         $productValue->setScope($columnInfo->getScope());
         $product->addValue($productValue);
     }
     return $productValue;
 }
 function let(ProductManager $productManager, UserContext $userContext, CurrencyManager $currencyManager, Locale $en, Locale $de, AttributeRepository $attributeRepository, AbstractProductValue $productValue, CatalogContext $catalogContext, ProductBuilder $productBuilder, ProductMassActionManager $massActionManager, MetricFactory $metricFactory)
 {
     $en->getCode()->willReturn('en_US');
     $de->getCode()->willReturn('de_DE');
     $userContext->getCurrentLocale()->willReturn($en);
     $userContext->getUserLocales()->willReturn([$en, $de]);
     $catalogContext->setLocaleCode(Argument::any())->willReturn($catalogContext);
     $productManager->createProductValue()->willReturn($productValue);
     $productValue->setAttribute(Argument::any())->willReturn($productValue);
     $productValue->setLocale(Argument::any())->willReturn($productValue);
     $productValue->setScope(Argument::any())->willReturn($productValue);
     $productValue->addPrice(Argument::any())->willReturn($productValue);
     $productManager->getAttributeRepository()->willReturn($attributeRepository);
     $this->beConstructedWith($productManager, $userContext, $currencyManager, $catalogContext, $productBuilder, $massActionManager, $metricFactory, ['product_price' => 'Pim\\Bundle\\CatalogBundle\\Model\\ProductPrice', 'product_media' => 'Pim\\Bundle\\CatalogBundle\\Model\\ProductMedia']);
 }
예제 #5
0
    public function process($item)
    {
        $sku       = $item['sku'];
        $attribute = $this->productManager->getIdentifierAttribute();
        $product   = $this->productManager->findByIdentifier($sku);

        if (!$product) {
            $product = $this->productManager->createProduct();
            $value   = $this->productManager->createProductValue();
            $value->setAttribute($attribute);
            $value->setData($sku);
            $product->addValue($value);
            $this->stepExecution->incrementSummaryInfo('create');

            return $product;

        } else {

            $data = current(((array) $item));
            $this->stepExecution->incrementSummaryInfo('skip');

            throw new InvalidItemException(sprintf('Skip the existing %s product', $sku), $data);
        }
    }
 /**
  * Create a value
  *
  * @param AbstractAttribute $attribute
  * @param string            $localeCode
  * @param string            $channelCode
  *
  * @return ProductValueInterface
  */
 protected function createValue(AbstractAttribute $attribute, $localeCode = null, $channelCode = null)
 {
     $value = $this->productManager->createProductValue();
     $value->setAttribute($attribute);
     if ($attribute->isLocalizable()) {
         $value->setLocale($localeCode);
     }
     if ($attribute->isScopable()) {
         $value->setScope($channelCode);
     }
     if ('pim_catalog_price_collection' === $attribute->getAttributeType()) {
         foreach ($this->currencyManager->getActiveCodes() as $code) {
             $value->addPrice($this->createProductPrice($code));
         }
     }
     return $value;
 }