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


PHP Category::getResource方法代码示例

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


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

示例1: getChildrenIds

 /**
  * @param \Magento\Catalog\Model\Category $category
  * @param boolean $recursive
  * @return int[]
  */
 public function getChildrenIds(Category $category, $recursive = false)
 {
     $cacheKey = $category->getId() . '_' . (int) $recursive;
     if (!isset($this->childrenIds[$cacheKey])) {
         $connection = $category->getResource()->getReadConnection();
         $select = $connection->select()->from($category->getResource()->getEntityTable(), 'entity_id')->where($connection->quoteIdentifier('path') . ' LIKE :c_path');
         $bind = ['c_path' => $category->getPath() . '/%'];
         if (!$recursive) {
             $select->where($connection->quoteIdentifier('level') . ' <= :c_level');
             $bind['c_level'] = $category->getLevel() + 1;
         }
         $this->childrenIds[$cacheKey] = $connection->fetchCol($select, $bind);
     }
     return $this->childrenIds[$cacheKey];
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:20,代码来源:ChildrenCategoriesProvider.php

示例2: processDelete

 /**
  * @param Category $category
  * @return void
  */
 public function processDelete(Category $category)
 {
     /** @var \Magento\Catalog\Model\ResourceModel\Category $resourceModel */
     $resourceModel = $category->getResource();
     /**
      * Update children count for all parent categories
      */
     $parentIds = $category->getParentIds();
     if ($parentIds) {
         $childDecrease = $category->getChildrenCount() + 1;
         // +1 is itself
         $data = ['children_count' => new \Zend_Db_Expr('children_count - ' . $childDecrease)];
         $where = ['entity_id IN(?)' => $parentIds];
         $resourceModel->getConnection()->update($resourceModel->getEntityTable(), $data, $where);
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:20,代码来源:AggregateCount.php

示例3: _getCategoryAttribute

 /**
  * Retrieve category attributes
  *
  * @param string $attributeCode
  * @param int|array $categoryIds
  * @param int $storeId
  * @return array
  */
 protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId)
 {
     $linkField = $this->metadataPool->getMetadata(CategoryInterface::class)->getLinkField();
     $identifierFiled = $this->metadataPool->getMetadata(CategoryInterface::class)->getIdentifierField();
     $connection = $this->getConnection();
     if (!isset($this->_categoryAttributes[$attributeCode])) {
         $attribute = $this->_catalogCategory->getResource()->getAttribute($attributeCode);
         $this->_categoryAttributes[$attributeCode] = ['entity_type_id' => $attribute->getEntityTypeId(), 'attribute_id' => $attribute->getId(), 'table' => $attribute->getBackend()->getTable(), 'is_global' => $attribute->getIsGlobal(), 'is_static' => $attribute->isStatic()];
         unset($attribute);
     }
     if (!is_array($categoryIds)) {
         $categoryIds = [$categoryIds];
     }
     $attributeTable = $this->_categoryAttributes[$attributeCode]['table'];
     $select = $connection->select();
     $bind = [];
     if ($this->_categoryAttributes[$attributeCode]['is_static']) {
         $select->from($this->getTable('catalog_category_entity'), ['value' => $attributeCode, 'entity_id' => 'entity_id'])->where('entity_id IN(?)', $categoryIds);
     } elseif ($this->_categoryAttributes[$attributeCode]['is_global'] || $storeId == 0) {
         $select->from(['t1' => $this->getTable('catalog_category_entity')], [$identifierFiled])->joinLeft(['e' => $attributeTable], "t1.{$linkField} = e.{$linkField}", ['value'])->where("t1.{$identifierFiled} IN(?)", $categoryIds)->where('e.attribute_id = :attribute_id')->where('e.store_id = ?', 0);
         $bind['attribute_id'] = $this->_categoryAttributes[$attributeCode]['attribute_id'];
     } else {
         $valueExpr = $connection->getCheckSql('t2.value_id > 0', 't2.value', 't1.value');
         $select->from(['t1' => $attributeTable], [$identifierFiled => 'e.' . $identifierFiled, 'value' => $valueExpr])->joinLeft(['t2' => $attributeTable], "t1.{$linkField} = t2.{$linkField} AND t1.attribute_id = t2.attribute_id AND t2.store_id = :store_id", [])->joinLeft(['e' => $this->getTable('catalog_category_entity')], "e.{$linkField} = t1.{$linkField}", [])->where('t1.store_id = ?', 0)->where('t1.attribute_id = :attribute_id')->where("e.entity_id IN(?)", $categoryIds)->group('e.entity_id');
         $bind['attribute_id'] = $this->_categoryAttributes[$attributeCode]['attribute_id'];
         $bind['store_id'] = $storeId;
     }
     $rowSet = $connection->fetchAll($select, $bind);
     $attributes = [];
     foreach ($rowSet as $row) {
         $attributes[$row[$identifierFiled]] = $row['value'];
     }
     unset($rowSet);
     foreach ($categoryIds as $categoryId) {
         if (!isset($attributes[$categoryId])) {
             $attributes[$categoryId] = null;
         }
     }
     return $attributes;
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:48,代码来源:Url.php

示例4: _getCategoryAttribute

 /**
  * Retrieve category attributes
  *
  * @param string $attributeCode
  * @param int|array $categoryIds
  * @param int $storeId
  * @return array
  */
 protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId)
 {
     $adapter = $this->_getWriteAdapter();
     if (!isset($this->_categoryAttributes[$attributeCode])) {
         $attribute = $this->_catalogCategory->getResource()->getAttribute($attributeCode);
         $this->_categoryAttributes[$attributeCode] = ['entity_type_id' => $attribute->getEntityTypeId(), 'attribute_id' => $attribute->getId(), 'table' => $attribute->getBackend()->getTable(), 'is_global' => $attribute->getIsGlobal(), 'is_static' => $attribute->isStatic()];
         unset($attribute);
     }
     if (!is_array($categoryIds)) {
         $categoryIds = [$categoryIds];
     }
     $attributeTable = $this->_categoryAttributes[$attributeCode]['table'];
     $select = $adapter->select();
     $bind = [];
     if ($this->_categoryAttributes[$attributeCode]['is_static']) {
         $select->from($this->getTable('catalog_category_entity'), ['value' => $attributeCode, 'entity_id' => 'entity_id'])->where('entity_id IN(?)', $categoryIds);
     } elseif ($this->_categoryAttributes[$attributeCode]['is_global'] || $storeId == 0) {
         $select->from($attributeTable, ['entity_id', 'value'])->where('attribute_id = :attribute_id')->where('store_id = ?', 0)->where('entity_id IN(?)', $categoryIds);
         $bind['attribute_id'] = $this->_categoryAttributes[$attributeCode]['attribute_id'];
     } else {
         $valueExpr = $adapter->getCheckSql('t2.value_id > 0', 't2.value', 't1.value');
         $select->from(['t1' => $attributeTable], ['entity_id', 'value' => $valueExpr])->joinLeft(['t2' => $attributeTable], 't1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id = :store_id', [])->where('t1.store_id = ?', 0)->where('t1.attribute_id = :attribute_id')->where('t1.entity_id IN(?)', $categoryIds);
         $bind['attribute_id'] = $this->_categoryAttributes[$attributeCode]['attribute_id'];
         $bind['store_id'] = $storeId;
     }
     $rowSet = $adapter->fetchAll($select, $bind);
     $attributes = [];
     foreach ($rowSet as $row) {
         $attributes[$row['entity_id']] = $row['value'];
     }
     unset($rowSet);
     foreach ($categoryIds as $categoryId) {
         if (!isset($attributes[$categoryId])) {
             $attributes[$categoryId] = null;
         }
     }
     return $attributes;
 }
开发者ID:nja78,项目名称:magento2,代码行数:46,代码来源:Url.php

示例5: getObject

 public function getObject(Category $category)
 {
     /** @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
     $productCollection = $category->getProductCollection();
     $productCollection = $productCollection->addMinimalPrice();
     $category->setProductCount($productCollection->getSize());
     $transport = new DataObject();
     $this->eventManager->dispatch('algolia_category_index_before', ['category' => $category, 'custom_data' => $transport]);
     $customData = $transport->getData();
     $storeId = $category->getStoreId();
     $category->getUrlInstance()->setStore($storeId);
     $path = '';
     foreach ($category->getPathIds() as $categoryId) {
         if ($path != '') {
             $path .= ' / ';
         }
         $path .= $this->getCategoryName($categoryId, $storeId);
     }
     $image_url = null;
     try {
         $image_url = $category->getImageUrl();
     } catch (\Exception $e) {
         /* no image, no default: not fatal */
     }
     $data = ['objectID' => $category->getId(), 'name' => $category->getName(), 'path' => $path, 'level' => $category->getLevel(), 'url' => $category->getUrl(), 'include_in_menu' => $category->getIncludeInMenu(), '_tags' => ['category'], 'popularity' => 1, 'product_count' => $category->getProductCount()];
     if (!empty($image_url)) {
         $data['image_url'] = $image_url;
     }
     foreach ($this->config->getCategoryAdditionalAttributes($storeId) as $attribute) {
         $value = $category->getData($attribute['attribute']);
         $attribute_resource = $category->getResource()->getAttribute($attribute['attribute']);
         if ($attribute_resource) {
             $value = $attribute_resource->getFrontend()->getValue($category);
         }
         if (isset($data[$attribute['attribute']])) {
             $value = $data[$attribute['attribute']];
         }
         if ($value) {
             $data[$attribute['attribute']] = $value;
         }
     }
     $data = array_merge($data, $customData);
     foreach ($data as &$data0) {
         $data0 = $this->try_cast($data0);
     }
     return $data;
 }
开发者ID:algolia,项目名称:algoliasearch-magento-2,代码行数:47,代码来源:CategoryHelper.php

示例6: validateCategory

 /**
  * Validate category process
  *
  * @param  Category $category
  * @return void
  * @throws \Magento\Framework\Model\Exception
  */
 protected function validateCategory(Category $category)
 {
     $useConfigFields = [];
     foreach ($this->useConfigFields as $field) {
         if (!$category->getData($field)) {
             $useConfigFields[] = $field;
         }
     }
     $category->setData('use_post_data_config', $useConfigFields);
     $validate = $category->validate();
     if ($validate !== true) {
         foreach ($validate as $code => $error) {
             if ($error === true) {
                 $attribute = $category->getResource()->getAttribute($code)->getFrontend()->getLabel();
                 throw new \Magento\Framework\Model\Exception(__('Attribute "%1" is required.', $attribute));
             } else {
                 throw new \Magento\Framework\Model\Exception($error);
             }
         }
     }
     $category->unsetData('use_post_data_config');
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:29,代码来源:WriteService.php

示例7: getResource

 /**
  * {@inheritdoc}
  */
 public function getResource()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getResource');
     if (!$pluginInfo) {
         return parent::getResource();
     } else {
         return $this->___callPlugins('getResource', func_get_args(), $pluginInfo);
     }
 }
开发者ID:HaonanXu,项目名称:der-snack-backup,代码行数:12,代码来源:Interceptor.php


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