本文整理汇总了PHP中Pim\Component\Catalog\Model\ProductInterface::getCategories方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface::getCategories方法的具体用法?PHP ProductInterface::getCategories怎么用?PHP ProductInterface::getCategories使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Component\Catalog\Model\ProductInterface
的用法示例。
在下文中一共展示了ProductInterface::getCategories方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
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']);
}
示例2: setFieldData
/**
* {@inheritdoc}
*
* Expected data input format : ["category_code"]
*/
public function setFieldData(ProductInterface $product, $field, $data, array $options = [])
{
$this->checkData($field, $data);
$categories = [];
foreach ($data as $categoryCode) {
$category = $this->getCategory($categoryCode);
if (null === $category) {
throw InvalidArgumentException::expected($field, 'existing category code', 'setter', 'category', $categoryCode);
} else {
$categories[] = $category;
}
}
$oldCategories = $product->getCategories();
foreach ($oldCategories as $category) {
$product->removeCategory($category);
}
foreach ($categories as $category) {
$product->addCategory($category);
}
}
示例3:
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' => []]);
}
示例4: buildCategories
/**
* @param ProductInterface $product
*
* @return array
*/
protected function buildCategories(ProductInterface $product)
{
$result = [];
foreach ($product->getCategories() as $category) {
$result[] = ['id' => $category->getId(), 'code' => $category->getCode(), 'rootId' => $category->getRoot()];
}
return $result;
}
示例5: denormalizeCategories
/**
* Denormalize product categories
*
* @param string $data
* @param string $format
* @param array $context
* @param ProductInterface $product
*/
protected function denormalizeCategories($data, $format, array $context, ProductInterface $product)
{
foreach ($product->getCategories() as $category) {
$product->removeCategory($category);
}
$categoryCodes = strlen($data) > 0 ? explode(",", $data) : [];
foreach ($categoryCodes as $categoryCode) {
$product->addCategory($this->serializer->denormalize($categoryCode, $this->categoryClass, $format, $context));
}
}