本文整理汇总了PHP中Pim\Component\Catalog\Model\ProductInterface::getGroups方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface::getGroups方法的具体用法?PHP ProductInterface::getGroups怎么用?PHP ProductInterface::getGroups使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Component\Catalog\Model\ProductInterface
的用法示例。
在下文中一共展示了ProductInterface::getGroups方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function it_does_not_validate_products_with_multiple_variant_group($context, $onlyOneVariantGroup, ProductInterface $mug, CustomGroupInterface $mugVariantGroup, CustomGroupInterface $otherGroup, GroupTypeInterface $variantType, ConstraintViolationBuilderInterface $violation)
{
$mug->getGroups()->willReturn([$mugVariantGroup, $otherGroup]);
$mugVariantGroup->getType()->willReturn($variantType);
$mugVariantGroup->__toString()->willReturn('mug');
$otherGroup->getType()->willReturn($variantType);
$otherGroup->__toString()->willReturn('other');
$variantType->isVariant()->willReturn(true);
$mug->getIdentifier()->willReturn('mug');
$context->buildViolation($onlyOneVariantGroup->message, ['%groups%' => 'mug, other', '%product%' => 'mug'])->shouldBeCalled()->willReturn($violation);
$this->validate($mug, $onlyOneVariantGroup);
}
示例2:
function it_sets_variant_group_field($groupRepository, ProductInterface $product, GroupInterface $shirt, GroupInterface $cross, GroupInterface $up, GroupTypeInterface $variantType, GroupTypeInterface $nonVariantType)
{
$groupRepository->findOneByIdentifier('shirt')->willReturn($shirt);
$shirt->getType()->willReturn($variantType);
$variantType->isVariant()->willReturn(true);
$product->getGroups()->willReturn([$up, $cross]);
$up->getType()->willReturn($nonVariantType);
$nonVariantType->isVariant()->willReturn(false);
$cross->getType()->willReturn($variantType);
$variantType->isVariant()->willReturn(true);
$product->removeGroup($cross)->shouldBeCalled();
$product->addGroup($shirt)->shouldBeCalled();
$this->setFieldData($product, 'variant_group', 'shirt');
}
示例3: array
function it_normalizes_product(SerializerInterface $serializer, ProductInterface $product, FamilyInterface $family, Completeness $completeness)
{
$serializer->implement('Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface');
$this->setSerializer($serializer);
$product->getFamily()->willReturn($family);
$product->getGroups()->willReturn([]);
$product->getValues()->willReturn([]);
$product->getCompletenesses()->willReturn([$completeness]);
$product->getCreated()->willReturn(null);
$product->getUpdated()->willReturn(null);
$product->isEnabled()->willReturn(true);
$serializer->normalize($family, 'mongodb_json', [])->willReturn('family normalization');
$serializer->normalize($completeness, 'mongodb_json', [])->willReturn(['completenessCode' => 'completeness normalization']);
$this->normalize($product, 'mongodb_json', [])->shouldReturn([ProductNormalizer::FAMILY_FIELD => 'family normalization', ProductNormalizer::COMPLETENESSES_FIELD => array('completenessCode' => 'completeness normalization'), ProductNormalizer::ENABLED_FIELD => true]);
}
示例4:
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']);
}
示例5: getRequiredAttributeCodes
/**
* Returns the required attribute codes for a product
*
* @param ProductInterface $product
*
* @return array
*/
public function getRequiredAttributeCodes(ProductInterface $product)
{
$codes = [];
if ($product->getFamily()) {
$codes = $this->getFamilyAttributeCodes($product->getFamily());
}
foreach ($product->getGroups() as $group) {
$codes = array_merge($codes, $this->getGroupAttributeCodes($group));
}
if ($product->getId()) {
foreach ($product->getValues() as $value) {
$codes[] = $value->getAttribute()->getCode();
}
}
return array_unique($codes);
}
示例6: setFieldData
/**
* {@inheritdoc}
*
* Expected data input format : ["group_code"]
*/
public function setFieldData(ProductInterface $product, $field, $data, array $options = [])
{
$this->checkData($field, $data);
$groups = [];
foreach ($data as $groupCode) {
$group = $this->groupRepository->findOneByIdentifier($groupCode);
if (null === $group) {
throw InvalidArgumentException::expected($field, 'existing group code', 'setter', 'groups', $groupCode);
} else {
$groups[] = $group;
}
}
$oldGroups = $product->getGroups();
foreach ($oldGroups as $group) {
$product->removeGroup($group);
}
foreach ($groups as $group) {
$product->addGroup($group);
}
}
示例7: setFieldData
/**
* {@inheritdoc}
*
* Expected data input format : "variant_group_code"
*/
public function setFieldData(ProductInterface $product, $field, $data, array $options = [])
{
$this->checkData($field, $data);
if (null !== $data) {
$variantGroup = $this->groupRepository->findOneByIdentifier($data);
if (null === $variantGroup) {
throw InvalidArgumentException::expected($field, 'existing variant group code', 'setter', 'variant_group', $data);
}
if (!$variantGroup->getType()->isVariant()) {
throw InvalidArgumentException::expected($field, 'variant group code', 'setter', 'variant_group', $data);
}
}
$existingGroups = $product->getGroups();
foreach ($existingGroups as $group) {
if ($group->getType()->isVariant()) {
$product->removeGroup($group);
}
}
if (null !== $data) {
$product->addGroup($variantGroup);
}
}
示例8:
function it_normalizes_an_existing_product_without_family_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)
{
$mongoFactory->createMongoId('product1')->willReturn($mongoId);
$mongoFactory->createMongoDate()->willReturn($mongoDate);
$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(null);
$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, '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' => []]);
}
示例9: denormalizeGroups
/**
* Denormalize product groups
*
* @param string $data
* @param string $format
* @param array $context
* @param ProductInterface $product
*/
protected function denormalizeGroups($data, $format, array $context, ProductInterface $product)
{
foreach ($product->getGroups() as $group) {
$product->removeGroup($group);
}
$groupCodes = strlen($data) > 0 ? explode(",", $data) : [];
foreach ($groupCodes as $groupCode) {
$product->addGroup($this->serializer->denormalize($groupCode, $this->groupClass, $format, $context));
}
}