本文整理汇总了PHP中Pim\Bundle\CatalogBundle\Model\GroupInterface::getType方法的典型用法代码示例。如果您正苦于以下问题:PHP GroupInterface::getType方法的具体用法?PHP GroupInterface::getType怎么用?PHP GroupInterface::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Bundle\CatalogBundle\Model\GroupInterface
的用法示例。
在下文中一共展示了GroupInterface::getType方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
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']);
}
示例2: normalizeVariantGroupValues
/**
* 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;
}
示例3: onSuccess
/**
* 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);
}
示例4:
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);
}
示例5:
function it_adds_a_violation_if_a_group_contains_axis_attributes($context, GroupInterface $group, GroupType $type, VariantGroupAxis $constraint, AttributeInterface $axis)
{
$group->getId()->willReturn(null);
$group->getType()->willReturn($type);
$group->getCode()->willReturn('xsell');
$type->isVariant()->willReturn(false);
$group->getAxisAttributes()->willReturn([$axis]);
$violationData = ['%group%' => 'xsell'];
$context->addViolation($constraint->unexpectedAxisMessage, $violationData)->shouldBeCalled();
$this->validate($group, $constraint);
}
示例6:
function it_adds_a_violation_if_axis_attributes_are_invalid($context, GroupInterface $variantGroup, GroupType $type, VariantGroupAxis $constraint, ConstraintViolationBuilderInterface $violation, AttributeInterface $invalidAxis)
{
$variantGroup->getId()->willReturn(12);
$variantGroup->getType()->willReturn($type);
$variantGroup->getCode()->willReturn('tshirt');
$type->isVariant()->willReturn(true);
$variantGroup->getAxisAttributes()->willReturn([$invalidAxis]);
$invalidAxis->getAttributeType()->willReturn(AttributeTypes::TEXT);
$invalidAxis->getCode()->willReturn('name');
$violationData = ['%group%' => 'tshirt', '%attribute%' => 'name'];
$context->buildViolation($constraint->invalidAxisMessage, $violationData)->shouldBeCalled()->willReturn($violation);
$this->validate($variantGroup, $constraint);
}
示例7: normalizeVariantGroupValues
/**
* {@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;
}
示例8:
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]);
}
示例9:
function it_sets_groups_field($groupRepository, ProductInterface $product, GroupInterface $pack, GroupInterface $cross, GroupInterface $up, GroupTypeInterface $nonVariantType)
{
$groupRepository->findOneByIdentifier('pack')->willReturn($pack);
$groupRepository->findOneByIdentifier('cross')->willReturn($cross);
$product->getGroups()->willReturn([$up]);
$up->getType()->willReturn($nonVariantType);
$nonVariantType->isVariant()->willReturn(false);
$product->removeGroup($up)->shouldBeCalled();
$pack->getType()->willReturn($nonVariantType);
$nonVariantType->isVariant()->willReturn(false);
$cross->getType()->willReturn($nonVariantType);
$nonVariantType->isVariant()->willReturn(false);
$product->addGroup($pack)->shouldBeCalled();
$product->addGroup($cross)->shouldBeCalled();
$this->setFieldData($product, 'groups', ['pack', 'cross']);
}
示例10:
function it_adds_a_violation_if_variant_group_template_contains_a_unique_attribute(GroupInterface $variantGroup, GroupType $type, ProductTemplateInterface $template, VariantGroupValues $constraint, $attributeRepository, $context)
{
$variantGroup->getType()->willReturn($type);
$variantGroup->getCode()->willReturn('tshirt');
$type->isVariant()->willReturn(true);
$variantGroup->getProductTemplate()->willReturn($template);
$variantGroup->getAxisAttributes()->willReturn([]);
$attributeRepository->findUniqueAttributeCodes()->willReturn(['sku', 'barcode']);
$template->getValuesData()->willReturn(['sku' => 'SKU-001']);
$violationData = ['%group%' => 'tshirt', '%attributes%' => '"sku"'];
$context->addViolation($constraint->message, $violationData)->shouldBeCalled();
$this->validate($variantGroup, $constraint);
$template->getValuesData()->willReturn(['sku' => 'SKU-001', 'barcode' => 01122334455]);
$violationData = ['%group%' => 'tshirt', '%attributes%' => '"sku", "barcode"'];
$context->addViolation($constraint->message, $violationData)->shouldBeCalled();
$this->validate($variantGroup, $constraint);
}
示例11:
function it_is_not_attribute_removable_with_group_containing_attribute(AttributeInterface $attribute, GroupInterface $group, GroupTypeInterface $groupType, ArrayCollection $groupAttributes)
{
$groupType->isVariant()->willReturn(true);
$groupAttributes->contains($attribute)->willReturn(true);
$group->getType()->willReturn($groupType);
$group->getAxisAttributes()->willReturn($groupAttributes);
$group->addProduct($this)->willReturn($this);
$this->addGroup($group);
$this->isAttributeRemovable($attribute)->shouldReturn(false);
}
示例12:
function it_does_not_add_violation_when_validating_product_in_groups_with_unique_combination_of_axis_attributes($context, $productRepository, GroupInterface $tShirtVariantGroup, GroupTypeInterface $tShirtGroupType, ProductInterface $redTShirtProduct, AttributeInterface $sizeAttribute, AttributeInterface $colorAttribute, ProductValueInterface $sizeProductValue, ProductValueInterface $redColorProductValue, UniqueVariantAxis $uniqueVariantAxisConstraint)
{
$tShirtVariantGroup->getId()->willReturn(1);
$tShirtVariantGroup->getLabel()->willReturn('TShirts');
$tShirtVariantGroup->getType()->willReturn($tShirtGroupType);
$tShirtGroupType->isVariant()->willReturn(true);
$tShirtVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]);
$sizeAttribute->getCode()->willReturn('size');
$sizeAttribute->isBackendTypeReferenceData()->willReturn(false);
$colorAttribute->getCode()->willReturn('color');
$colorAttribute->isBackendTypeReferenceData()->willReturn(false);
$redTShirtProduct->getVariantGroup()->willReturn($tShirtVariantGroup);
$redTShirtProduct->getId()->willReturn(1);
$redTShirtProduct->getValue('size')->willReturn($sizeProductValue);
$redTShirtProduct->getValue('color')->willReturn($redColorProductValue);
$sizeProductValue->getOption()->willReturn('XL');
$redColorProductValue->getOption()->willReturn('Red');
$criteria = [['attribute' => $sizeAttribute, 'option' => 'XL'], ['attribute' => $colorAttribute, 'option' => 'Red']];
$productRepository->findAllForVariantGroup($tShirtVariantGroup, $criteria)->willReturn([]);
$context->buildViolation()->shouldNotBeCalled(Argument::cetera());
$this->validate($redTShirtProduct, $uniqueVariantAxisConstraint);
}
示例13:
function it_adds_a_violation_when_validating_product_in_groups_with_non_unique_combination_of_axis_attributes($context, $productRepository, GroupInterface $tShirtVariantGroup, GroupTypeInterface $tShirtGroupType, GroupInterface $clothesVariantGroup, GroupTypeInterface $clothesGroupType, ProductInterface $redTShirtProduct, AttributeInterface $sizeAttribute, AttributeInterface $colorAttribute, ProductValueInterface $sizeProductValue, ProductValueInterface $colorProductValue, ProductInterface $redTShirtProduct2, UniqueVariantAxis $uniqueVariantAxisConstraint)
{
$redTShirtProduct->getGroups()->willReturn([$tShirtVariantGroup, $clothesVariantGroup]);
$tShirtVariantGroup->getId()->willReturn(1);
$tShirtVariantGroup->getLabel()->willReturn('TShirts');
$tShirtVariantGroup->getType()->willReturn($tShirtGroupType);
$tShirtGroupType->isVariant()->willReturn(true);
$tShirtVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]);
$clothesVariantGroup->getId()->willReturn(2);
$clothesVariantGroup->getLabel()->willReturn('Clothes');
$clothesVariantGroup->getType()->willReturn($clothesGroupType);
$clothesGroupType->isVariant()->willReturn(true);
$clothesVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]);
$sizeAttribute->getCode()->willReturn('size');
$colorAttribute->getCode()->willReturn('color');
$redTShirtProduct->getValue('size')->willReturn($sizeProductValue);
$redTShirtProduct->getValue('color')->willReturn($colorProductValue);
$redTShirtProduct->getId()->willReturn(1);
$sizeProductValue->getOption()->willReturn('XL');
$colorProductValue->getOption()->willReturn('Red');
$redTShirtProduct2->getGroups()->willReturn([$clothesVariantGroup]);
$redTShirtProduct2->getValue('size')->willReturn($sizeProductValue);
$redTShirtProduct2->getValue('color')->willReturn($colorProductValue);
$redTShirtProduct2->getId()->willReturn(2);
$criteria = [['attribute' => $sizeAttribute, 'option' => 'XL'], ['attribute' => $colorAttribute, 'option' => 'Red']];
$productRepository->findAllForVariantGroup($tShirtVariantGroup, $criteria)->willReturn([]);
$productRepository->findAllForVariantGroup($clothesVariantGroup, $criteria)->willReturn([$redTShirtProduct2]);
$context->addViolation('Group "%variant group%" already contains another product with values "%values%"', ['%variant group%' => 'Clothes', '%values%' => 'size: XL, color: Red'])->shouldBeCalled();
$this->validate($redTShirtProduct, $uniqueVariantAxisConstraint);
}