作者:noglitchy
项目:pim-community-de
function it_provides_formatted_batch_config_for_the_job(GroupInterface $oroTshirt)
{
$oroTshirt->getCode()->willReturn('oro_tshirt');
$this->setGroup($oroTshirt);
$this->setFilters([['id', 'IN', ['22', '7']]]);
$this->getBatchConfig()->shouldReturn('{\\"filters\\":[[\\"id\\",\\"IN\\",[\\"22\\",\\"7\\"]]],\\"actions\\":{\\"field\\":\\"variant_group\\",\\"value\\":\\"oro_tshirt\\"}}');
}
作者:vpetrovyc
项目:pim-community-de
function it_fails_if_the_group_code_is_not_found($groupRepository, ProductInterface $product, GroupInterface $pack, GroupTypeInterface $nonVariantType)
{
$groupRepository->findOneByIdentifier('not valid code')->willReturn(null);
$pack->getType()->willReturn($nonVariantType);
$nonVariantType->isVariant()->willReturn(false);
$this->shouldThrow(InvalidArgumentException::expected('variant_group', 'existing variant group code', 'setter', 'variant_group', 'not valid code'))->during('setFieldData', [$product, 'variant_group', 'not valid code']);
}
作者:noglitchy
项目:pim-community-de
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' => []]);
}
作者:noglitchy
项目:pim-community-de
function it_throws_an_error_if_type_is_unknown(GroupInterface $group)
{
$group->setCode('mycode')->shouldBeCalled();
$group->getId()->willReturn(null);
$values = ['code' => 'mycode', 'type' => 'UNKNOWN'];
$this->shouldThrow(new \InvalidArgumentException('Type "UNKNOWN" does not exist'))->during('update', [$group, $values, []]);
}
作者:qrz-i
项目:pim-community-de
/**
* Bind products
*
* @param GroupInterface $group
* @param array $appendProducts
* @param array $removeProducts
*/
protected function bindProducts(GroupInterface $group, array $appendProducts, array $removeProducts)
{
foreach ($appendProducts as $product) {
$group->addProduct($product);
}
foreach ($removeProducts as $product) {
$group->removeProduct($product);
}
}
作者:ashutosh-srija
项目:findit_akene
/**
* Normalize the variant group values
*
* @param GroupInterface $group
* @param string $format
* @param array $context
*
* @return array
*/
protected function normalizeVariantGroupValues(GroupInterface $group, $format, array $context)
{
$valuesData = [];
if ($group->getType()->isVariant() && null !== $group->getProductTemplate()) {
$template = $group->getProductTemplate();
$valuesData = $template->getValuesData();
}
return $valuesData;
}
作者:noglitchy
项目:pim-community-de
/**
* @param VariantGroupAxis $constraint
* @param GroupInterface $variantGroup
*/
protected function validateAttributeAxis(VariantGroupAxis $constraint, GroupInterface $variantGroup)
{
$allowedTypes = [AttributeTypes::OPTION_SIMPLE_SELECT, AttributeTypes::REFERENCE_DATA_SIMPLE_SELECT];
foreach ($variantGroup->getAxisAttributes() as $attribute) {
if (!in_array($attribute->getAttributeType(), $allowedTypes)) {
$this->addInvalidAxisViolation($constraint, $variantGroup->getCode(), $attribute->getCode());
}
}
}
作者:ashutosh-srija
项目:findit_akene
function it_validates_products_with_one_variant_group($context, $onlyOneVariantGroup, ProductInterface $mug, GroupInterface $mugVariantGroup, GroupInterface $otherGroup, GroupTypeInterface $variantType, GroupTypeInterface $groupType)
{
$mug->getGroups()->willReturn([$mugVariantGroup, $otherGroup]);
$mugVariantGroup->getType()->willReturn($variantType);
$otherGroup->getType()->willReturn($groupType);
$variantType->isVariant()->willReturn(true);
$groupType->isVariant()->willReturn(false);
$context->addViolation(Argument::any())->shouldNotBeCalled();
$this->validate($mug, $onlyOneVariantGroup);
}
作者:vpetrovyc
项目:pim-community-de
/**
* Call when form is valid
*
* @param GroupInterface $group
*/
protected function onSuccess(GroupInterface $group)
{
$appendProducts = $this->form->get('appendProducts')->getData();
$removeProducts = $this->form->get('removeProducts')->getData();
$options = ['add_products' => $appendProducts, 'remove_products' => $removeProducts];
if ($group->getType()->isVariant()) {
$options['copy_values_to_products'] = true;
}
$this->groupSaver->save($group, $options);
}
作者:Cope
项目:pim-community-de
function it_throws_an_error_if_axis_is_updated(GroupInterface $variantGroup)
{
$variantGroup->setCode('mycode')->shouldBeCalled();
$variantGroup->getId()->willReturn(42);
$attribute = new Attribute();
$attribute->setCode('other');
$variantGroup->getAxisAttributes()->willReturn(new ArrayCollection([$attribute]));
$values = ['code' => 'mycode', 'axis' => ['main_color']];
$this->shouldThrow(new \InvalidArgumentException('Attributes: This property cannot be changed.'))->during('update', [$variantGroup, $values, []]);
}
作者:jacko97
项目:pim-community-de
/**
* Get missing axis codes of a product given a variant group
*
* @param ProductInterface $product
* @param GroupInterface $variantGroup
*
* @return array
*/
protected function getMissingAxisCodes(ProductInterface $product, GroupInterface $variantGroup)
{
$missingAxisCodes = [];
foreach ($variantGroup->getAxisAttributes() as $attribute) {
$value = $product->getValue($attribute->getCode());
if (null === $value || null === $value->getData()) {
$missingAxisCodes[] = $attribute->getCode();
}
}
return $missingAxisCodes;
}
作者:paulclarki
项目:pim-community-de
function it_throws_an_exception_if_media_of_variant_group_is_not_found($normalizer, $denormalizer, ArrayCollection $productValuesCollection, ArrayCollection $mediaCollection, ProductMediaInterface $media, GroupInterface $variantGroup, ProductTemplateInterface $productTemplate, ProductValueInterface $productValue)
{
$variantGroup->getProductTemplate()->willReturn($productTemplate);
$variantGroup->getCode()->willReturn('my_variant_group');
$productTemplate->getValuesData()->willReturn([$productValue]);
$denormalizer->denormalize([$productValue], 'ProductValue[]', 'json')->willReturn($productValuesCollection);
$productValuesCollection->filter(Argument::cetera())->willReturn($mediaCollection);
$mediaCollection->toArray()->willReturn([$media]);
$normalizer->normalize([$media], 'csv', ['field_name' => 'media', 'prepare_copy' => true, 'identifier' => 'my_variant_group'])->willThrow(new FileNotFoundException('upload/path/img.jpg'));
$this->shouldThrow(new InvalidItemException('The file "upload/path/img.jpg" does not exist', ['item' => 'my_variant_group', 'uploadDirectory' => 'upload/path/']))->duringProcess($variantGroup);
}
作者:ashutosh-srija
项目:findit_akene
function it_returns_non_eligible_attributes($attributeRepository, GroupInterface $group, ProductTemplateInterface $template, AttributeInterface $length, AttributeInterface $name, AttributeInterface $color, AttributeInterface $identifier, Collection $collection)
{
$group->getProductTemplate()->willReturn($template);
$group->getAxisAttributes()->willReturn($collection);
$collection->toArray()->willReturn([$length]);
$template->getValuesData()->willReturn(['name' => 'foo', 'color' => 'bar']);
$attributeRepository->findOneByIdentifier('name')->willReturn($name);
$attributeRepository->findOneByIdentifier('color')->willReturn($color);
$attributeRepository->findBy(['unique' => true])->willReturn([$name, $identifier]);
$attributes = [$length, $name, $color, $identifier];
$this->getNonEligibleAttributes($group)->shouldReturn($attributes);
}
作者:umpirsk
项目:pim-community-de
/**
* Prepares media files present in the product template of the variant group for export.
* Returns an array of files to be copied from 'filePath' to 'exportPath'.
*
* @param GroupInterface $group
*
* @throws InvalidItemException If a media file is not found
*
* @return array
*/
protected function prepareVariantGroupMedia(GroupInterface $group)
{
$mediaValues = $this->getProductTemplateMediaValues($group->getProductTemplate());
if (count($mediaValues) < 1) {
return [];
}
try {
return $this->normalizer->normalize($mediaValues, $this->format, ['field_name' => 'media', 'prepare_copy' => true, 'identifier' => $group->getCode()]);
} catch (FileNotFoundException $e) {
throw new InvalidItemException($e->getMessage(), ['item' => $group->getCode(), 'uploadDirectory' => $this->uploadDirectory]);
}
}
作者:noglitchy
项目:pim-community-de
function it_provides_formatted_batch_config_for_the_job(GroupInterface $officeGroup, GroupInterface $bedroomGroup, ArrayCollection $groupCollection)
{
$officeGroup->getCode()->willReturn('office_room');
$bedroomGroup->getCode()->willReturn('bedroom');
$groupCollection->add($officeGroup);
$groupCollection->add($bedroomGroup);
$this->setGroups($groupCollection);
$groupCollection->map(Argument::type('closure'))->willReturn($groupCollection);
$groupCollection->toArray()->willReturn(['office_room', 'bedroom']);
$this->setFilters([['id', 'IN', ['22', '7']]]);
$this->getBatchConfig()->shouldReturn('{\\"filters\\":[[\\"id\\",\\"IN\\",[\\"22\\",\\"7\\"]]],\\"actions\\":[{\\"field\\":\\"groups\\",\\"value\\":[\\"office_room\\",\\"bedroom\\"]}]}');
}
作者:jacko97
项目:pim-community-de
/**
* Validate variant group product template values
*
* @param GroupInterface $variantGroup
* @param Constraint $constraint
*/
protected function validateProductTemplateValues(GroupInterface $variantGroup, Constraint $constraint)
{
$template = $variantGroup->getProductTemplate();
$valuesData = $template->getValuesData();
$forbiddenAttrCodes = $this->attributeRepository->findUniqueAttributeCodes();
foreach ($variantGroup->getAxisAttributes() as $axisAttribute) {
$forbiddenAttrCodes[] = $axisAttribute->getCode();
}
$invalidAttrCodes = array_intersect($forbiddenAttrCodes, array_keys($valuesData));
if (count($invalidAttrCodes) > 0) {
$this->context->addViolation($constraint->message, array('%group%' => $variantGroup->getCode(), '%attributes%' => $this->formatValues($invalidAttrCodes)));
}
}
作者:jacko97
项目:pim-community-de
function it_does_not_copy_values_to_products_when_template_is_empty(GroupInterface $variantGroup, ProductTemplateInterface $productTemplate, Collection $productCollection, ProductInterface $productOne, ProductInterface $productTwo, $productTplApplier, $stepExecution)
{
$variantGroup->getId()->willReturn(42);
$stepExecution->incrementSummaryInfo('update')->shouldBeCalled();
$variantGroup->getProductTemplate()->willReturn($productTemplate);
$productTemplate->getValuesData()->willReturn([]);
$variantGroup->getProducts()->willReturn($productCollection);
$productCollection->isEmpty()->willReturn(false);
$productCollection->toArray()->willReturn([$productOne, $productTwo]);
$productCollection->count()->willReturn(2);
$productTplApplier->apply($productTemplate, [$productOne, $productTwo])->shouldNotBeCalled();
$this->write([$variantGroup]);
}
作者:VinceBLO
项目:pim-community-de
/**
* {@inheritdoc}
*/
protected function normalizeVariantGroupValues(GroupInterface $group, $format, array $context)
{
if (!$group->getType()->isVariant() || null === $group->getProductTemplate()) {
return [];
}
$valuesData = $group->getProductTemplate()->getValuesData();
$values = $this->valuesDenormalizer->denormalize($valuesData, 'ProductValue[]', 'json');
$normalizedValues = [];
foreach ($values as $value) {
$normalizedValues = array_replace($normalizedValues, $this->serializer->normalize($value, $format, ['entity' => 'product'] + $context));
}
ksort($normalizedValues);
return $normalizedValues;
}
作者:jacko97
项目:pim-community-de
function it_saves_a_variant_group_and_copies_values_to_products($optionsResolver, $objectManager, $templateApplier, GroupInterface $group, GroupType $type, ProductInterface $product, ProductTemplateInterface $template, ArrayCollection $products)
{
$optionsResolver->resolveSaveOptions(['copy_values_to_products' => true])->willReturn(['flush' => true, 'copy_values_to_products' => true, 'add_products' => [], 'remove_products' => []]);
$group->getType()->willReturn($type);
$group->getCode()->willReturn('my_code');
$objectManager->persist($group)->shouldBeCalled();
$objectManager->flush()->shouldBeCalled();
$type->isVariant()->willReturn(true);
$group->getProductTemplate()->willReturn($template);
$group->getProducts()->willReturn($products);
$products->toArray()->willReturn([$product]);
$templateApplier->apply($template, [$product])->shouldBeCalled();
$this->save($group, ['copy_values_to_products' => true]);
}
作者:noglitchy
项目:pim-community-de
function it_adds_a_violation_when_validates_a_product_with_missing_value_for_an_axe_of_its_variant_group($context, ProductInterface $product, GroupInterface $tShirtVariantGroup, AttributeInterface $sizeAttribute, AttributeInterface $colorAttribute, ProductValueInterface $sizeValue, ProductValueInterface $identifierValue, HasVariantAxes $constraint, ConstraintViolationBuilderInterface $violation)
{
$tShirtVariantGroup->getCode()->willReturn('tshirt');
$tShirtVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]);
$sizeAttribute->getCode()->willReturn('size');
$colorAttribute->getCode()->willReturn('color');
$product->getIdentifier()->willReturn($identifierValue);
$product->getVariantGroup()->willReturn($tShirtVariantGroup);
$product->getValue('size')->willReturn($sizeValue);
$product->getValue('color')->willReturn(null);
$sizeValue->getData()->willReturn('XL');
$context->buildViolation('The product "%product%" is in the variant group "%variant%" but it misses the following axes: %axes%.', ['%product%' => $identifierValue, '%variant%' => 'tshirt', '%axes%' => 'color'])->shouldBeCalled()->willReturn($violation);
$this->validate($product, $constraint);
}