本文整理汇总了PHP中Pim\Component\Catalog\Model\ProductInterface::getVariantGroup方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface::getVariantGroup方法的具体用法?PHP ProductInterface::getVariantGroup怎么用?PHP ProductInterface::getVariantGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Component\Catalog\Model\ProductInterface
的用法示例。
在下文中一共展示了ProductInterface::getVariantGroup方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: use
function it_normalizes_the_properties_of_the_product($filter, $serializer, ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value, FamilyInterface $family, ArrayCollection $values, \ArrayIterator $iterator, ProductValueInterface $identifier)
{
$values->getIterator()->willReturn($iterator);
$family->getCode()->willReturn('my_family');
$product->getFamily()->willReturn($family);
$product->getGroupCodes()->willReturn([]);
$product->getVariantGroup()->willReturn(null);
$product->getCategoryCodes()->willReturn([]);
$product->isEnabled()->willReturn(true);
$value->getAttribute()->willReturn($attribute);
$attribute->getCode()->willReturn('name');
$product->getIdentifier()->willReturn($identifier);
$identifier->getData()->willReturn('my_code');
$product->getValues()->willReturn($values);
$filter->filterCollection($values, 'pim.transform.product_value.structured', Argument::type('array'))->shouldBeCalled()->willReturn($values);
$iterator->rewind()->willReturn(null);
$valueCount = 1;
$iterator->valid()->will(function () use(&$valueCount) {
return $valueCount-- > 0;
});
$iterator->current()->willReturn($value);
$iterator->next()->willReturn(null);
$context = ['filter_types' => ['pim.transform.product_value.structured']];
$serializer->normalize($value, 'standard', $context)->willReturn(['locale' => null, 'scope' => null, 'value' => 'foo']);
$created = new \DateTime('2010-06-23');
$product->getCreated()->willReturn($created);
$serializer->normalize($created, 'standard')->willReturn('2010-06-23T00:00:00+01:00');
$updated = new \DateTime('2010-06-23 23:00:00');
$product->getUpdated()->willReturn($updated);
$serializer->normalize($updated, 'standard')->willReturn('2010-06-23T23:00:00+01:00');
$this->normalize($product, 'standard', $context)->shouldReturn(['identifier' => 'my_code', 'family' => 'my_family', 'groups' => [], 'variant_group' => null, 'categories' => [], 'enabled' => true, 'values' => ['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']]], 'created' => '2010-06-23T00:00:00+01:00', 'updated' => '2010-06-23T23:00:00+01:00']);
}
示例2:
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);
}
示例3: validateProduct
/**
* Validate product
*
* @param ProductInterface $product
* @param Constraint $constraint
*/
protected function validateProduct(ProductInterface $product, Constraint $constraint)
{
$group = $product->getVariantGroup();
if (null === $group) {
return;
}
$criteria = $this->prepareQueryCriterias($group, $product, $constraint);
$matches = $this->getMatchingProducts($group, $product, $criteria);
if (count($matches) !== 0) {
$values = [];
foreach ($criteria as $item) {
$data = $item['attribute']->isBackendTypeReferenceData() ? $item['referenceData']['data'] : $item['option'];
$values[] = sprintf('%s: %s', $item['attribute']->getCode(), (string) $data);
}
$this->addExistingCombinationViolation($constraint, $group->getLabel(), implode(', ', $values));
}
}
示例4: use
function it_normalizes_the_properties_of_the_product(ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value, ArrayCollection $values, \ArrayIterator $iterator, $filter, $normalizer)
{
$values->getIterator()->willReturn($iterator);
$product->getFamily()->willReturn(null);
$product->getGroupCodes()->willReturn([]);
$product->getVariantGroup()->willReturn(null);
$product->getCategoryCodes()->willReturn([]);
$product->isEnabled()->willReturn(true);
$value->getAttribute()->willReturn($attribute);
$attribute->getCode()->willReturn('name');
$product->getValues()->willReturn($values);
$filter->filterCollection($values, 'pim.transform.product_value.structured', Argument::type('array'))->shouldBeCalled()->willReturn($values);
$iterator->rewind()->willReturn(null);
$valueCount = 1;
$iterator->valid()->will(function () use(&$valueCount) {
return $valueCount-- > 0;
});
$iterator->current()->willReturn($value);
$iterator->next()->willReturn(null);
$normalizer->normalize($values, 'json', Argument::any())->willReturn(['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']]]);
$this->normalize($product, 'json')->shouldReturn(['family' => null, 'groups' => [], 'variant_group' => null, 'categories' => [], 'enabled' => true, 'values' => ['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']]]]);
}
示例5: setProductValuesFromVariantGroup
/**
* @param ProductInterface $product
*/
protected function setProductValuesFromVariantGroup(ProductInterface $product)
{
$variantGroup = $product->getVariantGroup();
if ($variantGroup !== null && $variantGroup->getProductTemplate() !== null) {
$template = $variantGroup->getProductTemplate();
$this->templateUpdater->update($template, [$product]);
}
}
示例6:
function it_adds_a_violation_when_validating_product_in_groups_with_non_unique_combination_of_axis_attributes($context, $productRepository, GroupInterface $tShirtVariantGroup, ProductInterface $redTShirtProduct, AttributeInterface $sizeAttribute, AttributeInterface $colorAttribute, ProductValueInterface $sizeProductValue, ProductValueInterface $colorProductValue, ProductInterface $redTShirtProduct2, UniqueVariantAxis $uniqueVariantAxisConstraint, ConstraintViolationBuilderInterface $violation)
{
$redTShirtProduct->getVariantGroup()->willReturn($tShirtVariantGroup);
$tShirtVariantGroup->getId()->willReturn(1);
$tShirtVariantGroup->getLabel()->willReturn('TShirts');
$tShirtVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]);
$sizeAttribute->getCode()->willReturn('size');
$sizeAttribute->isBackendTypeReferenceData()->willReturn(true);
$sizeAttribute->getReferenceDataName()->willReturn('ref_size');
$colorAttribute->getCode()->willReturn('color');
$colorAttribute->isBackendTypeReferenceData()->willReturn(true);
$colorAttribute->getReferenceDataName()->willReturn('ref_color');
$redTShirtProduct->getValue('size')->willReturn($sizeProductValue);
$redTShirtProduct->getValue('color')->willReturn($colorProductValue);
$redTShirtProduct->getId()->willReturn(1);
$sizeProductValue->getData()->willReturn('XL');
$sizeProductValue->getOption()->willReturn(null);
$colorProductValue->getData()->willReturn('Red');
$colorProductValue->getOption()->willReturn(null);
$criteria = [['attribute' => $sizeAttribute, 'referenceData' => ['name' => 'ref_size', 'data' => 'XL']], ['attribute' => $colorAttribute, 'referenceData' => ['name' => 'ref_color', 'data' => 'Red']]];
$productRepository->findAllForVariantGroup($tShirtVariantGroup, $criteria)->shouldBeCalled()->willReturn([$redTShirtProduct2]);
$context->buildViolation('Group "%variant group%" already contains another product with values "%values%"', ['%variant group%' => 'TShirts', '%values%' => 'size: XL, color: Red'])->shouldBeCalled()->willReturn($violation);
$this->validate($redTShirtProduct, $uniqueVariantAxisConstraint);
}
示例7: updateProductVariantValues
/**
* Updates product with its variant group values to ensure that values coming from variant group are always
* applied after the product values (if a product value is updated and should come from variant group)
*
* @param ProductInterface $product
* @param array $data
*/
protected function updateProductVariantValues(ProductInterface $product, array $data)
{
$variantGroup = $product->getVariantGroup();
$shouldEraseData = false;
if (null !== $variantGroup && null !== $variantGroup->getProductTemplate()) {
$template = $variantGroup->getProductTemplate();
foreach (array_keys($data) as $field) {
if ($template->hasValueForAttributeCode($field) || null === $product->getValue($field)) {
$shouldEraseData = true;
}
}
if ($shouldEraseData) {
$this->templateUpdater->update($template, [$product]);
}
}
}
示例8: getGroups
/**
* @param ProductInterface $product
*
* @return array
*/
protected function getGroups(ProductInterface $product)
{
$groups = [];
if ($product->getGroupCodes()) {
$groups = $product->getGroupCodes();
if ($product->getVariantGroup()) {
$variantGroup = $product->getVariantGroup()->getCode();
$groups = array_diff($groups, [$variantGroup]);
}
}
return $groups;
}
示例9: normalizeGroups
/**
* @param ProductInterface $product
*
* @return array
*/
private function normalizeGroups(ProductInterface $product)
{
$groupCodes = [];
if (count($product->getGroupCodes()) > 0) {
$groupCodes = $product->getGroupCodes();
if (null !== $product->getVariantGroup()) {
$variantGroupCode = $product->getVariantGroup()->getCode();
$groupCodes = array_diff($groupCodes, [$variantGroupCode]);
}
}
return $groupCodes;
}