作者:abdeldaye
项目:pim-community-de
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]);
}
作者:a2xchi
项目:pim-community-de
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']);
}
作者:a2xchi
项目:pim-community-de
function it_provide_product_completeness_if_family_is_not_defined(ProductInterface $product, ChannelInterface $mobile, LocaleInterface $en)
{
$product->getFamily()->willReturn(null);
$en->getCode()->willReturn('en_US');
$mobile->getCode()->willReturn('mobile');
$this->getProductCompleteness($product, [$mobile], [$en], 'en_US')->shouldReturn([['channels' => [['completeness' => null, 'missing' => []]], 'stats' => ['total' => 0, 'complete' => 0], 'locale' => '']]);
}
作者:abdeldaye
项目:pim-community-de
function it_copies_simple_select_value_to_a_product_value($builder, $attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValueInterface $fromProductValue, ProductValueInterface $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->getData()->willReturn($attributeOption);
$toProductValue->setOption($attributeOption)->shouldBeCalledTimes(3);
$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]);
}
}
作者:a2xchi
项目:pim-community-de
function it_normalizes_groups($normalizer, $structureVersionProvider, $versionManager, $versionNormalizer, $localizedConverter, GroupInterface $tshirt, GroupTypeInterface $groupType, Version $oldestLog, Version $newestLog, ArrayCollection $products, ProductInterface $product, \ArrayIterator $productsIterator)
{
$options = ['decimal_separator' => ',', 'date_format' => 'dd/MM/yyyy'];
$tshirt->getType()->willReturn($groupType);
$groupType->isVariant()->willReturn(true);
$variantNormalized = ['code' => 'my_variant', 'axis' => ['color', 'size'], 'type' => 'variant', 'values' => ['number' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'metric' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'prices' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'date' => ['data' => '2015-01-31', 'locale' => null, 'scope' => null]]];
$valuesLocalized = ['number' => ['data' => '12,5000', 'locale' => null, 'scope' => null], 'metric' => ['data' => '12,5000', 'locale' => null, 'scope' => null], 'prices' => ['data' => '12,50', 'locale' => null, 'scope' => null], 'date' => ['data' => '31/01/2015', 'locale' => null, 'scope' => null]];
$normalizer->normalize($tshirt, 'json', $options)->willReturn($variantNormalized);
$localizedConverter->convertToLocalizedFormats($variantNormalized['values'], $options)->willReturn($valuesLocalized);
$structureVersionProvider->getStructureVersion()->willReturn(1);
$versionManager->getOldestLogEntry($tshirt)->willReturn($oldestLog);
$versionManager->getNewestLogEntry($tshirt)->willReturn($newestLog);
$versionNormalizer->normalize($oldestLog, 'internal_api')->willReturn('normalized_oldest_log');
$versionNormalizer->normalize($newestLog, 'internal_api')->willReturn('normalized_newest_log');
$products->getIterator()->willReturn($productsIterator);
$productsIterator->rewind()->shouldBeCalled();
$productsCount = 1;
$productsIterator->valid()->will(function () use(&$productsCount) {
return $productsCount-- > 0;
});
$productsIterator->next()->shouldBeCalled();
$productsIterator->current()->will(new ReturnPromise([$product]));
$product->getId()->willReturn(42);
$tshirt->getId()->willReturn(12);
$tshirt->getProducts()->willReturn($products);
$this->normalize($tshirt, 'internal_api', $options)->shouldReturn(['code' => 'my_variant', 'axis' => ['color', 'size'], 'type' => 'variant', 'values' => $valuesLocalized, 'products' => [42], 'meta' => ['id' => 12, 'form' => 'pim-variant-group-edit-form', 'structure_version' => 1, 'model_type' => 'variant_group', 'created' => 'normalized_oldest_log', 'updated' => 'normalized_newest_log']]);
}
作者:abdeldaye
项目:pim-community-de
/**
* 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);
}
作者:a2xchi
项目:pim-community-de
/**
* @param ProductInterface $product
*/
protected function incrementCount(ProductInterface $product)
{
if ($product->getId()) {
$this->stepExecution->incrementSummaryInfo('process');
} else {
$this->stepExecution->incrementSummaryInfo('create');
}
}
作者:a2xchi
项目:pim-community-de
function it_applies_on_related_products($saver, RemoveEvent $event, CategoryInterface $object, ProductInterface $product)
{
$saver->saveAll([$product])->shouldBeCalled();
$event->getSubject()->willReturn($object);
$object->getProducts()->willReturn([$product]);
$product->removeCategory($object)->shouldBeCalled();
$this->postRemove($event)->shouldReturn(null);
}
作者:abdeldaye
项目:pim-community-de
/**
* 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);
}
作者:pierallar
项目:pim-community-de
/**
* As boolean attribute does not support "null" value (only true/false),
* there are some problems to make out what should really be added to the product (specially with optional attributes)
* What we add in product:
* | old value | new value | attribute is in family | should be added in product |
* | null | false | yes | no |
* | null | false | no | yes |
*
* This method should be removed when boolean attribute will be rework to support 3 states: true/false/null
*
* @deprecated will be removed in 1.7
*
* @param ProductInterface $product product to update
* @param AttributeInterface $attribute attribute
* @param mixed $data new value
*
* @return bool
*/
private function shouldBeSetInProduct(ProductInterface $product, AttributeInterface $attribute, $data)
{
$family = $product->getFamily();
if (null !== $family && in_array($attribute->getCode(), $product->getFamily()->getAttributeCodes()) && false === $data) {
return false;
}
return true;
}
作者:alexisfroge
项目:pim-community-de
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' => []]]]);
}
作者:alexisfroge
项目:pim-community-de
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);
}
作者:abdeldaye
项目:pim-community-de
/**
* 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);
}
作者:alexisfroge
项目:pim-community-de
function it_returns_flat_data_without_media(ChannelInterface $channel, ChannelManager $channelManager, ProductInterface $product, Serializer $serializer)
{
$product->getValues()->willReturn([]);
$this->setDecimalSeparator(',');
$serializer->normalize($product, 'flat', ['scopeCode' => 'foobar', 'localeCodes' => '', 'decimal_separator' => ',', 'date_format' => 'yyyy-MM-dd'])->willReturn(['normalized_product']);
$channelManager->getChannelByCode('foobar')->willReturn($channel);
$this->setChannel('foobar');
$this->process($product)->shouldReturn(['media' => [], 'product' => ['normalized_product']]);
}
作者:a2xchi
项目:pim-community-de
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);
}
作者:abdeldaye
项目:pim-community-de
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']);
}
作者:a2xchi
项目:pim-community-de
function it_should_removes_an_attribute_data_multi_select_value_to_a_product_value(AttributeInterface $attribute, ProductInterface $product, ProductValueInterface $productValue, AttributeOptionInterface $attributeOption, $attrOptionRepository)
{
$attribute->getCode()->willReturn('tshirt_style');
$attrOptionRepository->findOneByIdentifier('tshirt_style.vneck')->willReturn($attributeOption);
$product->getValue('tshirt_style', 'fr_FR', 'mobile')->willReturn($productValue);
$productValue->removeOption($attributeOption)->shouldBeCalled();
$data = ['vneck'];
$this->removeAttributeData($product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']);
}
作者:a2xchi
项目:pim-community-de
/**
* @param ProductInterface $product
* @param AttributeInterface $attribute
* @param array $attributeOptions
* @param string|null $locale
* @param string|null $scope
*/
protected function removeOptions(ProductInterface $product, AttributeInterface $attribute, $attributeOptions, $locale, $scope)
{
$productValue = $product->getValue($attribute->getCode(), $locale, $scope);
if (null !== $productValue) {
foreach ($attributeOptions as $attributeOption) {
$productValue->removeOption($attributeOption);
}
}
}
作者:a2xchi
项目:pim-community-de
/**
* 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;
}
作者:abdeldaye
项目:pim-community-de
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);
}