当前位置: 首页>>代码示例>>PHP>>正文


PHP ProductInterface::getCategories方法代码示例

本文整理汇总了PHP中Pim\Bundle\CatalogBundle\Model\ProductInterface::getCategories方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface::getCategories方法的具体用法?PHP ProductInterface::getCategories怎么用?PHP ProductInterface::getCategories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pim\Bundle\CatalogBundle\Model\ProductInterface的用法示例。


在下文中一共展示了ProductInterface::getCategories方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1:

 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' => []]);
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:25,代码来源:ProductNormalizerSpec.php

示例2: getProductCountByTree

 /**
  * {@inheritdoc}
  */
 public function getProductCountByTree(ProductInterface $product)
 {
     $categories = $product->getCategories();
     $categoryIds = array();
     foreach ($categories as $category) {
         $categoryIds[] = $category->getId();
     }
     $categoryRepository = $this->entityManager->getRepository($this->categoryClass);
     $categoryTable = $this->entityManager->getClassMetadata($this->categoryClass)->getTableName();
     $categoryIds = implode(',', $categoryIds);
     if (!empty($categoryIds)) {
         $sql = "SELECT" . "    tree.id AS tree_id," . "    COUNT(category.id) AS product_count" . "  FROM {$categoryTable} tree" . "  LEFT JOIN {$categoryTable} category" . "    ON category.root = tree.id" . " AND category.id IN ({$categoryIds})" . " WHERE tree.parent_id IS NULL" . " GROUP BY tree.id";
     } else {
         $sql = "SELECT" . "    tree.id AS tree_id," . "    '0' AS product_count" . "  FROM {$categoryTable} tree" . "  LEFT JOIN {$categoryTable} category" . "    ON category.root = tree.id" . " WHERE tree.parent_id IS NULL" . " GROUP BY tree.id";
     }
     $stmt = $this->entityManager->getConnection()->prepare($sql);
     $stmt->execute();
     $productCounts = $stmt->fetchAll();
     $trees = array();
     foreach ($productCounts as $productCount) {
         $tree = array();
         $tree['productCount'] = $productCount['product_count'];
         $tree['tree'] = $categoryRepository->find($productCount['tree_id']);
         $trees[] = $tree;
     }
     return $trees;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:30,代码来源:ProductCategoryRepository.php

示例3:

 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']);
 }
开发者ID:vpetrovych,项目名称:pim-community-dev,代码行数:9,代码来源:CategoryFieldAdderSpec.php

示例4: 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->categoryRepository->findOneByIdentifier($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);
     }
 }
开发者ID:vpetrovych,项目名称:pim-community-dev,代码行数:25,代码来源:CategoryFieldSetter.php

示例5:

 function it_returns_only_products_in_the_given_channel(ProductInterface $product1, ProductInterface $product2, Channel $channel, ArrayCollection $productCategories1, ArrayCollection $productCategories2, ArrayCollection $completenesses, Category $rootCategory, Category $category1, Category $category2, AbstractCompleteness $completeness1, AbstractCompleteness $completeness2)
 {
     $channel->getCategory()->willReturn($rootCategory);
     $channel->getId()->willReturn(2);
     $rootCategory->getId()->willReturn(1);
     $product1->getCategories()->willReturn($productCategories1);
     $product2->getCategories()->willReturn($productCategories2);
     $product1->getCompletenesses()->willReturn($completenesses);
     $product2->getCompletenesses()->willReturn($completenesses);
     $completenesses->toArray()->willReturn([$completeness1, $completeness2]);
     $completeness1->getChannel()->willReturn($channel);
     $completeness2->getChannel()->willReturn($channel);
     $completeness1->getRatio()->willReturn(100);
     $completeness2->getRatio()->willReturn(100);
     $productCategories1->toArray()->willReturn([$category1]);
     $productCategories2->toArray()->willReturn([$category2]);
     $category1->getRoot()->willReturn(1);
     $category2->getRoot()->willReturn(5);
     $this->apply($channel, [$product1, $product2])->shouldReturn([$product1]);
 }
开发者ID:rskonieczka,项目名称:MagentoConnectorBundle,代码行数:20,代码来源:ExportableProductFilterSpec.php

示例6: computeProductCategory

 /**
  * @param ProductInterface $product
  * @param array            $drupalProduct
  */
 protected function computeProductCategory(ProductInterface $product, array &$drupalProduct)
 {
     /** @var Category $category */
     foreach ($product->getCategories() as $category) {
         if ($category->getLevel() > 0) {
             $drupalProduct['categories'][$this->formatedRootCategories[$category->getRoot()]][] = $category->getCode();
         }
     }
 }
开发者ID:antoineguigan,项目名称:DrupalCommerceConnectorBundle,代码行数:13,代码来源:ProductNormalizer.php

示例7: getProductCategories

 /**
  * Get categories for the given product.
  *
  * @param ProductInterface  $product
  * @param MappingCollection $categoryMapping
  * @param string            $scopeCode
  *
  * @return array
  *
  * @throws CategoryNotFoundException
  */
 protected function getProductCategories(ProductInterface $product, MappingCollection $categoryMapping, $scopeCode)
 {
     $productCategories = [];
     $channelCategoryTree = $this->channelManager->getChannelByCode($scopeCode)->getCategory();
     foreach ($product->getCategories() as $category) {
         if ($category->getRoot() == $channelCategoryTree->getId()) {
             $prestashopCategoryId = $this->categoryMappingManager->getIdFromCategory($category, $this->prestashopUrl, $categoryMapping);
             if (!$prestashopCategoryId) {
                 throw new CategoryNotFoundException(sprintf('The category %s was not found. Please export categories first or add it to the root ' . 'category mapping', $category->getLabel()));
             }
             $productCategories[] = $prestashopCategoryId;
         }
     }
     return $productCategories;
 }
开发者ID:mejdoubimeriem,项目名称:prestashopconnector,代码行数:26,代码来源:ProductNormalizer.php

示例8: 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) : array();
     foreach ($categoryCodes as $categoryCode) {
         $product->addCategory($this->serializer->denormalize($categoryCode, $this->categoryClass, $format, $context));
     }
 }
开发者ID:vpetrovych,项目名称:pim-community-dev,代码行数:18,代码来源:ProductDenormalizer.php


注:本文中的Pim\Bundle\CatalogBundle\Model\ProductInterface::getCategories方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。