function it_hydrates_a_result_record(Builder $builder, Query $query, ProductInterface $product, Association $association, AssociationType $associationType, ProductInterface $associatedProduct1, ProductInterface $associatedProduct2, DocumentManager $documentManager, \Doctrine\ODM\MongoDB\Mapping\ClassMetadata $metadata, Collection $collection, ArrayIterator $arrayIterator)
 {
     $options = ['locale_code' => 'en_US', 'scope_code' => 'print', 'current_group_id' => null, 'attributes_configuration' => [], 'association_type_id' => 1, 'current_product' => $product];
     $builder->getQuery()->willReturn($query);
     $builder->hydrate(false)->willReturn($builder);
     $associatedProduct1->getId()->willReturn('550ae6b98ead0ed7778b46bb');
     $associatedProduct2->getId()->willReturn('550ae6b98abd0ec8778b46bb');
     $product->getAssociations()->willReturn([$association]);
     $association->getAssociationType()->willReturn($associationType);
     $associationType->getId()->willReturn(1);
     $association->getProducts()->willReturn([$associatedProduct1, $associatedProduct2]);
     $queryDefinition = ['type' => 1, 'sort' => ['normalizedData.is_associated' => -1, '_id' => 1], 'limit' => 10, 'skip' => 0, 'query' => ['_id' => ['$ne' => \MongoId::__set_state(['$id' => '550ae6b98ead0ee8778b46bb'])]], 'newObj' => []];
     $query->getQuery()->willReturn($queryDefinition);
     $query->getDocumentManager()->willReturn($documentManager);
     $documentManager->getDocumentCollection(Argument::any())->willReturn($collection);
     $documentManager->getClassMetadata(Argument::any())->willReturn($metadata);
     $metadata->getFieldNames()->willReturn(['id', 'created', 'updated', 'locale', 'scope', 'values', 'indexedValues', 'indexedValuesOutdated', 'family', 'familyId', 'categories', 'categoryIds', 'enabled', 'groups', 'groupIds', 'associations', 'completenesses', 'normalizedData']);
     $pipeline = [['$match' => ['_id' => ['$ne' => \MongoId::__set_state(['$id' => '550ae6b98ead0ee8778b46bb'])]]], ['$project' => ['id' => 1, 'created' => 1, 'updated' => 1, 'locale' => 1, 'scope' => 1, 'values' => 1, 'indexedValues' => 1, 'indexedValuesOutdated' => 1, 'family' => 1, 'familyId' => 1, 'categories' => 1, 'categoryIds' => 1, 'enabled' => 1, 'groups' => 1, 'groupIds' => 1, 'associations' => 1, 'completenesses' => 1, 'normalizedData' => 1, 'is_associated' => ['$cond' => [['$or' => [['$eq' => ['$_id', \MongoId::__set_state(['$id' => '550ae6b98ead0ed7778b46bb'])]], ['$eq' => ['$_id', \MongoId::__set_state(['$id' => '550ae6b98abd0ec8778b46bb'])]]]], 1, 0]]]], ['$sort' => ['is_associated' => -1]], ['$skip' => 0], ['$limit' => 10]];
     $collection->aggregate($pipeline)->willReturn($arrayIterator);
     $fixture = ['_id' => \MongoId::__set_state(['$id' => '550ae6b98ead0ee8778b46bb']), 'normalizedData' => [], 'sku' => ['attribute' => ['code' => 'sku', 'attributeType' => 'text', 'backendType' => 'text'], 'locale' => null, 'scope' => null, 'value' => 'mysku'], 'name' => ['attribute' => ['code' => 'name', 'attributeType' => 'text', 'backendType' => 'text'], 'locale' => 'fr_FR', 'scope' => null], 'desc' => ['attribute' => ['code' => 'desc', 'attributeType' => 'text', 'backendType' => 'text'], 'locale' => 'fr_FR', 'scope' => 'print'], 'is_associated' => 1];
     $arrayIterator->toArray()->willReturn([$fixture]);
     $rows = $this->hydrate($builder, $options);
     $rows->shouldHaveCount(1);
     $firstResult = $rows[0];
     $firstResult->shouldBeAnInstanceOf('\\Oro\\Bundle\\DataGridBundle\\Datasource\\ResultRecord');
 }
 function it_adds_product_value(ProductInterface $product, AttributeInterface $size)
 {
     $size->isLocalizable()->willReturn(false);
     $size->isScopable()->willReturn(false);
     $product->addValue(Argument::any())->shouldBeCalled();
     $this->addProductValue($product, $size);
 }
 function it_converts_metric_values_given_the_configured_base_unit_in_the_channel($converter, ProductValueInterface $weightValue, ProductValueInterface $surfaceValue, ProductValueInterface $nameValue, AttributeInterface $weight, AttributeInterface $surface, AttributeInterface $name, MetricInterface $weightMetric, MetricInterface $surfaceMetric, ProductInterface $product, ChannelInterface $channel)
 {
     $weightValue->getAttribute()->willReturn($weight);
     $weightValue->getData()->willReturn($weightMetric);
     $weight->getCode()->willReturn('weight');
     $weightMetric->getFamily()->willReturn('Weight');
     $weightMetric->getUnit()->willReturn('KILOGRAM');
     $weightMetric->getData()->willReturn(1);
     $surfaceValue->getAttribute()->willReturn($surface);
     $surfaceValue->getData()->willReturn($surfaceMetric);
     $surface->getCode()->willReturn('surface');
     $surfaceMetric->getFamily()->willReturn('Surface');
     $surfaceMetric->getUnit()->willReturn('METER_SQUARE');
     $surfaceMetric->getData()->willReturn(10);
     $nameValue->getAttribute()->willReturn($name);
     $nameValue->getData()->willReturn('foobar');
     $product->getValues()->willReturn(array($weightValue, $surfaceValue, $nameValue));
     $channel->getConversionUnits()->willReturn(array('weight' => 'GRAM'));
     $converter->setFamily('Weight')->shouldBeCalled();
     $converter->convert('KILOGRAM', 'GRAM', 1)->willReturn(0.001);
     $converter->setFamily('Surface')->shouldNotBeCalled();
     $weightMetric->setData(0.001)->shouldBeCalled();
     $weightMetric->setUnit('GRAM')->shouldBeCalled();
     $this->convert($product, $channel);
 }
 function it_provide_product_completeness_if_family_is_not_defined(ProductInterface $product, ChannelInterface $mobile, LocaleInterface $en, FamilyInterface $shirt)
 {
     $product->getFamily()->willReturn(null);
     $en->getCode()->willReturn('en_US');
     $mobile->getCode()->willReturn('mobile');
     $this->getProductCompleteness($product, [$mobile], [$en], 'en_US')->shouldReturn(['en_US' => ['channels' => ['mobile' => ['completeness' => null, 'missing' => []]], 'stats' => ['total' => 0, 'complete' => 0]]]);
 }
 function it_massively_insert_new_products_and_update_existing_products($documentManager, $collection, $normalizer, $mongoFactory, $pendingPersister, $eventDispatcher, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4)
 {
     $mongoFactory->createMongoId()->willReturn('my_mongo_id');
     $product1->getId()->willReturn("my_product_1");
     $product2->getId()->willReturn(null);
     $product3->getId()->willReturn("my_product_3");
     $product4->getId()->willReturn(null);
     $product1->setId(Argument::any())->shouldNotBeCalled();
     $product2->setId('my_mongo_id')->shouldBeCalled();
     $product3->setId(Argument::any())->shouldNotBeCalled();
     $product4->setId('my_mongo_id')->shouldBeCalled();
     $normalizer->normalize($product1, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_product_1', 'normalized_product_1']);
     $normalizer->normalize($product2, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_mongo_id', 'normalized_product_2']);
     $normalizer->normalize($product3, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_product_3', 'normalized_product_3']);
     $normalizer->normalize($product4, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_mongo_id', 'normalized_product_4']);
     $collection->batchInsert([['_id' => 'my_mongo_id', 'normalized_product_2'], ['_id' => 'my_mongo_id', 'normalized_product_4']])->shouldBeCalled();
     $collection->update(['_id' => 'my_product_1'], ['_id' => 'my_product_1', 'normalized_product_1'])->shouldBeCalled();
     $collection->update(['_id' => 'my_product_3'], ['_id' => 'my_product_3', 'normalized_product_3'])->shouldBeCalled();
     $pendingPersister->persistPendingVersions([$product1, $product2, $product3, $product4])->shouldBeCalled();
     $eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.pre_insert', Argument::any())->shouldBeCalled();
     $eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.pre_update', Argument::any())->shouldBeCalled();
     $eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.post_insert', Argument::any())->shouldBeCalled();
     $eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.post_update', Argument::any())->shouldBeCalled();
     $documentManager->clear()->shouldBeCalled();
     $this->write([$product1, $product2, $product3, $product4]);
 }
 function it_normalizes_an_existing_product_into_mongodb_document($mongoFactory, $serializer, ProductInterface $product, \MongoId $mongoId, \MongoDate $mongoDate, Association $assoc1, Association $assoc2, CategoryInterface $category1, CategoryInterface $category2, GroupInterface $group1, GroupInterface $group2, ProductValueInterface $value1, ProductValueInterface $value2, FamilyInterface $family)
 {
     $mongoFactory->createMongoId('product1')->willReturn($mongoId);
     $mongoFactory->createMongoDate()->willReturn($mongoDate);
     $family->getId()->willReturn(36);
     $category1->getId()->willReturn(12);
     $category2->getId()->willReturn(34);
     $group1->getId()->willReturn(56);
     $group2->getId()->willReturn(78);
     $product->getId()->willReturn('product1');
     $product->getCreated()->willReturn(null);
     $product->getFamily()->willReturn($family);
     $product->isEnabled()->willReturn(true);
     $product->getGroups()->willReturn([$group1, $group2]);
     $product->getCategories()->willReturn([$category1, $category2]);
     $product->getAssociations()->willReturn([$assoc1, $assoc2]);
     $product->getValues()->willReturn([$value1, $value2]);
     $context = ['_id' => $mongoId];
     $serializer->normalize($product, 'mongodb_json')->willReturn(['data' => 'data', 'completenesses' => 'completenesses']);
     $serializer->normalize($value1, 'mongodb_document', $context)->willReturn('my_value_1');
     $serializer->normalize($value2, 'mongodb_document', $context)->willReturn('my_value_2');
     $serializer->normalize($assoc1, 'mongodb_document', $context)->willReturn('my_assoc_1');
     $serializer->normalize($assoc2, 'mongodb_document', $context)->willReturn('my_assoc_2');
     $this->normalize($product, 'mongodb_document')->shouldReturn(['_id' => $mongoId, 'created' => $mongoDate, 'updated' => $mongoDate, 'family' => 36, 'enabled' => true, 'groupIds' => [56, 78], 'categoryIds' => [12, 34], 'associations' => ['my_assoc_1', 'my_assoc_2'], 'values' => ['my_value_1', 'my_value_2'], 'normalizedData' => ['data' => 'data'], 'completenesses' => []]);
 }
 function it_allows_setting_option_to_null(ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value)
 {
     $attribute->getCode()->willReturn('choice');
     $product->getValue('choice', null, null)->shouldBeCalled()->willReturn($value);
     $value->setOption(null)->shouldBeCalled();
     $this->setValue([$product], $attribute, null);
 }
 function it_copies_a_price_collection_value_to_a_product_value($builder, $attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValue $fromProductValue, ProductValue $toProductValue, ProductPriceInterface $price)
 {
     $fromLocale = 'fr_FR';
     $toLocale = 'fr_FR';
     $toScope = 'mobile';
     $fromScope = 'mobile';
     $fromAttribute->getCode()->willReturn('fromAttributeCode');
     $toAttribute->getCode()->willReturn('toAttributeCode');
     $attrValidatorHelper->validateLocale(Argument::cetera())->shouldBeCalled();
     $attrValidatorHelper->validateScope(Argument::cetera())->shouldBeCalled();
     $fromProductValue->getData()->willReturn([$price]);
     $price->getCurrency()->willReturn('USD');
     $price->getData()->willReturn(123);
     $product1->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
     $product1->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
     $product2->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn(null);
     $product2->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
     $product3->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
     $product3->getValue('toAttributeCode', $toLocale, $toScope)->willReturn(null);
     $product4->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
     $product4->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
     $builder->addProductValue($product3, $toAttribute, $toLocale, $toScope)->shouldBeCalledTimes(1)->willReturn($toProductValue);
     $builder->addPriceForCurrencyWithData($toProductValue, 'USD', 123)->shouldBeCalled();
     $products = [$product1, $product2, $product3, $product4];
     foreach ($products as $product) {
         $this->copyAttributeData($product, $product, $fromAttribute, $toAttribute, ['from_locale' => $fromLocale, 'to_locale' => $toLocale, 'from_scope' => $fromScope, 'to_scope' => $toScope]);
     }
 }
 function it_allows_setting_attribute_data_option_to_null(ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value)
 {
     $attribute->getCode()->willReturn('choice');
     $product->getValue('choice', 'fr_FR', 'mobile')->shouldBeCalled()->willReturn($value);
     $value->setOption(null)->shouldBeCalled();
     $this->setAttributeData($product, $attribute, null, ['locale' => 'fr_FR', 'scope' => 'mobile']);
 }
 /**
  * {@inheritdoc}
  */
 public function getProductCountByTree(ProductInterface $product)
 {
     $categories = $product->getCategories();
     $categoryIds = array();
     foreach ($categories as $category) {
         $categoryIds[] = $category->getId();
     }
     $categoryRepository = $this->entityManager->getRepository($this->categoryClass);
     $categoryTable = $this->entityManager->getClassMetadata($this->categoryClass)->getTableName();
     $categoryIds = implode(',', $categoryIds);
     if (!empty($categoryIds)) {
         $sql = "SELECT" . "    tree.id AS tree_id," . "    COUNT(category.id) AS product_count" . "  FROM {$categoryTable} tree" . "  LEFT JOIN {$categoryTable} category" . "    ON category.root = tree.id" . " AND category.id IN ({$categoryIds})" . " WHERE tree.parent_id IS NULL" . " GROUP BY tree.id";
     } else {
         $sql = "SELECT" . "    tree.id AS tree_id," . "    '0' AS product_count" . "  FROM {$categoryTable} tree" . "  LEFT JOIN {$categoryTable} category" . "    ON category.root = tree.id" . " WHERE tree.parent_id IS NULL" . " GROUP BY tree.id";
     }
     $stmt = $this->entityManager->getConnection()->prepare($sql);
     $stmt->execute();
     $productCounts = $stmt->fetchAll();
     $trees = array();
     foreach ($productCounts as $productCount) {
         $tree = array();
         $tree['productCount'] = $productCount['product_count'];
         $tree['tree'] = $categoryRepository->find($productCount['tree_id']);
         $trees[] = $tree;
     }
     return $trees;
 }
 function it_copies_multi_select_value_to_a_product_value($builder, $attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValue $fromProductValue, ProductValue $toProductValue, AttributeOptionInterface $attributeOption)
 {
     $fromLocale = 'fr_FR';
     $toLocale = 'fr_FR';
     $toScope = 'mobile';
     $fromScope = 'mobile';
     $fromAttribute->getCode()->willReturn('fromAttributeCode');
     $toAttribute->getCode()->willReturn('toAttributeCode');
     $attrValidatorHelper->validateLocale(Argument::cetera())->shouldBeCalled();
     $attrValidatorHelper->validateScope(Argument::cetera())->shouldBeCalled();
     $fromProductValue->getOptions()->willReturn([$attributeOption])->shouldBeCalled(3);
     $toProductValue->getOptions()->willReturn([$attributeOption]);
     $toProductValue->removeOption($attributeOption)->shouldBeCalled();
     $toProductValue->addOption($attributeOption)->shouldBeCalled();
     $product1->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
     $product1->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
     $product2->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn(null);
     $product2->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
     $product3->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
     $product3->getValue('toAttributeCode', $toLocale, $toScope)->willReturn(null);
     $product4->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
     $product4->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
     $builder->addProductValue($product3, $toAttribute, $toLocale, $toScope)->shouldBeCalledTimes(1)->willReturn($toProductValue);
     $products = [$product1, $product2, $product3, $product4];
     foreach ($products as $product) {
         $this->copyAttributeData($product, $product, $fromAttribute, $toAttribute, ['from_locale' => $fromLocale, 'to_locale' => $toLocale, 'from_scope' => $fromScope, 'to_scope' => $toScope]);
     }
 }
 /**
  * @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);
     }
 }
 /**
  * Set media in the product value
  *
  * @param ProductInterface       $product
  * @param AttributeInterface     $attribute
  * @param FileInfoInterface|null $fileInfo
  * @param string|null            $locale
  * @param string|null            $scope
  */
 protected function setMedia(ProductInterface $product, AttributeInterface $attribute, FileInfoInterface $fileInfo = null, $locale = null, $scope = null)
 {
     $value = $product->getValue($attribute->getCode(), $locale, $scope);
     if (null === $value) {
         $value = $this->productBuilder->addProductValue($product, $attribute, $locale, $scope);
     }
     $value->setMedia($fileInfo);
 }
 /**
  * Set data into product value
  *
  * @param ProductInterface   $product
  * @param AttributeInterface $attribute
  * @param mixed              $data
  * @param string             $locale
  * @param string             $scope
  */
 protected function setData(ProductInterface $product, AttributeInterface $attribute, $data, $locale, $scope)
 {
     $value = $product->getValue($attribute->getCode(), $locale, $scope);
     if (null === $value) {
         $value = $this->productBuilder->addProductValue($product, $attribute, $locale, $scope);
     }
     $value->setData($data);
 }
 function it_fails_if_one_of_the_associated_group_does_not_exist($productBuilder, $groupRepository, ProductInterface $product, AssociationInterface $xsellAssociation)
 {
     $product->getAssociations()->willReturn([$xsellAssociation]);
     $productBuilder->addMissingAssociations($product)->shouldBeCalled();
     $product->getAssociationForTypeCode('xsell')->willReturn($xsellAssociation);
     $groupRepository->findOneByIdentifier('not existing group')->willReturn(null);
     $this->shouldThrow(InvalidArgumentException::expected('associations', 'existing group code', 'adder', 'association', 'not existing group'))->during('addFieldData', [$product, 'associations', ['xsell' => ['groups' => ['not existing group'], 'products' => []]]]);
 }
 /**
  * Set option into the product value
  *
  * @param ProductInterface              $product
  * @param AttributeInterface            $attribute
  * @param AttributeOptionInterface|null $option
  * @param string|null                   $locale
  * @param string|null                   $scope
  */
 protected function setOption(ProductInterface $product, AttributeInterface $attribute, AttributeOptionInterface $option = null, $locale = null, $scope = null)
 {
     $value = $product->getValue($attribute->getCode(), $locale, $scope);
     if (null === $value) {
         $value = $this->productBuilder->addProductValue($product, $attribute, $locale, $scope);
     }
     $value->setOption($option);
 }
 function it_clears_cache(StepExecution $stepExecution, ProductInterface $product1, ProductInterface $product2)
 {
     $items = [$product1, $product2];
     $product1->getId()->willReturn('45');
     $product2->getId()->willReturn(null);
     $this->setStepExecution($stepExecution);
     $this->write($items);
 }
 function it_adds_products_to_the_selected_family_when_performing_the_operation(AbstractQuery $query, Family $mugs, ProductInterface $product1, ProductInterface $product2)
 {
     $this->setFamily($mugs);
     $this->setObjectsToMassEdit([$product1, $product2]);
     $product1->setFamily($mugs)->shouldBeCalled();
     $product2->setFamily($mugs)->shouldBeCalled();
     $this->perform();
 }
 function it_returns_flat_data_without_media(ChannelInterface $channel, ChannelManager $channelManager, ProductInterface $product, Serializer $serializer)
 {
     $product->getValues()->willReturn([]);
     $serializer->normalize($product, 'flat', ['scopeCode' => 'foobar', 'localeCodes' => ''])->willReturn(['normalized_product']);
     $channelManager->getChannelByCode('foobar')->willReturn($channel);
     $this->setChannel('foobar');
     $this->process($product)->shouldReturn(['media' => [], 'product' => ['normalized_product']]);
 }
 function it_creates_and_sets_geolocation_to_product_value($productBuilder, ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value)
 {
     $attribute->getCode()->shouldBeCalled()->willReturn('geolocation');
     $product->getValue('geolocation', 'FR', 'master')->shouldBeCalled()->willReturn(null);
     $productBuilder->addProductValue($product, $attribute, 'FR', 'master')->shouldBeCalled()->willReturn($value);
     $value->setData(Argument::type('CleverAge\\Bundle\\GeolocAttributeBundle\\Model\\Geolocation'))->shouldBeCalled();
     $this->setValue([$product], $attribute, ['latitude' => 12, 'longitude' => 12], 'FR', 'master');
 }
 /**
  * Returns the image path for an attribute of a product. If no image is found, returns null.
  *
  * @param ProductInterface   $product
  * @param AttributeInterface $attribute
  * @param string             $locale
  * @param string             $scope
  *
  * @return string|null
  */
 public function getImagePath(ProductInterface $product, AttributeInterface $attribute, $locale, $scope)
 {
     $productValue = $product->getValue($attribute->getCode(), $locale, $scope);
     $path = null;
     if (null !== $productValue->getMedia() && null !== $productValue->getMedia()->getKey()) {
         $path = sprintf('media/cache/thumbnail/%s', $productValue->getMedia()->getKey());
     }
     return $path;
 }
 function it_adds_category_field($categoryRepository, ProductInterface $product, CategoryInterface $mug, CategoryInterface $shirt, CategoryInterface $men)
 {
     $categoryRepository->findOneByIdentifier('mug')->willReturn($mug);
     $categoryRepository->findOneByIdentifier('shirt')->willReturn($shirt);
     $product->getCategories()->willReturn([$men]);
     $product->addCategory($mug)->shouldBeCalled();
     $product->addCategory($shirt)->shouldBeCalled();
     $this->addFieldData($product, 'categories', ['mug', 'shirt']);
 }
 function it_does_not_flush_object_manager_when_persisting(ManagerRegistry $registry, ObjectManager $objectManager, CompletenessManager $completenessManager, ProductInterface $product)
 {
     $registry->getManagerForClass(get_class($product->getWrappedObject()))->willReturn($objectManager);
     $objectManager->persist($product)->shouldBeCalled();
     $objectManager->flush()->shouldNotBeCalled();
     $completenessManager->schedule($product)->shouldBeCalled();
     $completenessManager->generateMissingForProduct($product)->shouldNotBeCalled();
     $this->persist($product, ['recalculate' => false, 'flush' => false, 'schedule' => true]);
 }
 function it_gets_association_status_for_a_given_product($magentoSoapClient, ProductInterface $product)
 {
     $magentoSoapClient->call('catalog_product_link.list', ['up_sell', 'sku-012', 'sku'])->willReturn('up_sell');
     $magentoSoapClient->call('catalog_product_link.list', ['cross_sell', 'sku-012', 'sku'])->willReturn('cross_sell');
     $magentoSoapClient->call('catalog_product_link.list', ['related', 'sku-012', 'sku'])->willReturn('related');
     $magentoSoapClient->call('catalog_product_link.list', ['grouped', 'sku-012', 'sku'])->willReturn('grouped');
     $product->getIdentifier()->willReturn('sku-012');
     $this->getAssociationsStatus($product)->shouldReturn(['up_sell' => 'up_sell', 'cross_sell' => 'cross_sell', 'related' => 'related', 'grouped' => 'grouped']);
 }
 function let(ProductManager $productManager, ExecutionContextInterface $context, Form $form, ProductInterface $product, ProductValueInterface $value)
 {
     $this->beConstructedWith($productManager);
     $product->getValue('sku')->willReturn($value);
     $form->getData()->willReturn($product);
     $context->getPropertyPath()->willReturn(self::PROPERTY_PATH);
     $context->getRoot()->willReturn($form);
     $this->initialize($context);
 }
 function it_applies_on_related_products($saver, RemoveEvent $event, CategoryInterface $object, ProductInterface $product)
 {
     $saver->saveAll([$product], ['flush' => 'expected_flush_value', 'recalculate' => false, 'schedule' => false])->shouldBeCalled();
     $event->getSubject()->willReturn($object);
     $event->getArgument('flush')->willReturn('expected_flush_value');
     $object->getProducts()->willReturn([$product]);
     $product->removeCategory($object)->shouldBeCalled();
     $this->postRemove($event)->shouldReturn(null);
 }
 function let(ProductRepositoryInterface $productRepository, UniqueValuesSet $uniqueValuesSet, ExecutionContextInterface $context, Form $form, ProductInterface $product, ProductValueInterface $value)
 {
     $this->beConstructedWith($productRepository, $uniqueValuesSet);
     $product->getValue('unique_attribute')->willReturn($value);
     $form->getData()->willReturn($product);
     $context->getPropertyPath()->willReturn(self::PROPERTY_PATH);
     $context->getRoot()->willReturn($form);
     $this->initialize($context);
 }
 /**
  * Remove prices from product value
  *
  * @param ProductInterface   $product
  * @param AttributeInterface $attribute
  * @param mixed              $data
  * @param string             $locale
  * @param string             $scope
  */
 protected function removePrices(ProductInterface $product, AttributeInterface $attribute, $data, $locale, $scope)
 {
     $productValue = $product->getValue($attribute->getCode(), $locale, $scope);
     if (null !== $productValue) {
         foreach ($data as $price) {
             $priceToRemove = $productValue->getPrice($price['currency']);
             $productValue->removePrice($priceToRemove);
         }
     }
 }
 /**
  * Is the given product complete for the given channel?
  *
  * @param ProductInterface $product
  * @param Channel          $channel
  *
  * @return bool
  */
 protected function isProductComplete(ProductInterface $product, Channel $channel)
 {
     $completenesses = $product->getCompletenesses()->toArray();
     foreach ($completenesses as $completeness) {
         if ($completeness->getChannel()->getId() === $channel->getId() && $completeness->getRatio() === 100) {
             return true;
         }
     }
     return false;
 }
 function it_dispatches_an_event_when_removing_a_category($eventDispatcher, $objectManager, CategoryInterface $category, ProductInterface $product1, ProductInterface $product2)
 {
     $category->isRoot()->willReturn(false);
     $category->getProducts()->willReturn([$product1, $product2]);
     $product1->removeCategory($category)->shouldBeCalled();
     $product2->removeCategory($category)->shouldBeCalled();
     $eventDispatcher->dispatch(CategoryEvents::PRE_REMOVE_CATEGORY, Argument::type('Symfony\\Component\\EventDispatcher\\GenericEvent'))->shouldBeCalled();
     $objectManager->remove($category)->shouldBeCalled();
     $this->remove($category, ['flush' => false]);
 }