本文整理汇总了PHP中Magento\Catalog\Model\Category::getPathIds方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::getPathIds方法的具体用法?PHP Category::getPathIds怎么用?PHP Category::getPathIds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Category
的用法示例。
在下文中一共展示了Category::getPathIds方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetPathIds
public function testGetPathIds()
{
$this->assertEquals([''], $this->_model->getPathIds());
$this->_model->setPathIds([1]);
$this->assertEquals([1], $this->_model->getPathIds());
$this->_model->unsetData();
$this->_model->setPath('1/2/3');
$this->assertEquals([1, 2, 3], $this->_model->getPathIds());
}
示例2: testGetPathIds
public function testGetPathIds()
{
$this->assertEquals(array(''), $this->_model->getPathIds());
$this->_model->setPathIds(array(1));
$this->assertEquals(array(1), $this->_model->getPathIds());
$this->_model->unsetData();
$this->_model->setPath('1/2/3');
$this->assertEquals(array(1, 2, 3), $this->_model->getPathIds());
}
示例3: getResetValue
/**
* Get filter value for reset current filter state
*
* @return mixed|null
*/
public function getResetValue()
{
if ($this->_appliedCategory) {
/**
* Revert path ids
*/
$pathIds = array_reverse($this->_appliedCategory->getPathIds());
$curCategoryId = $this->getLayer()->getCurrentCategory()->getId();
if (isset($pathIds[1]) && $pathIds[1] != $curCategoryId) {
return $pathIds[1];
}
}
return null;
}
示例4: changeParent
/**
* Move category to another parent node
*
* @param \Magento\Catalog\Model\Category $category
* @param \Magento\Catalog\Model\Category $newParent
* @param null|int $afterCategoryId
* @return $this
*/
public function changeParent(\Magento\Catalog\Model\Category $category, \Magento\Catalog\Model\Category $newParent, $afterCategoryId = null)
{
$childrenCount = $this->getChildrenCount($category->getId()) + 1;
$table = $this->getEntityTable();
$adapter = $this->_getWriteAdapter();
$levelFiled = $adapter->quoteIdentifier('level');
$pathField = $adapter->quoteIdentifier('path');
/**
* Decrease children count for all old category parent categories
*/
$adapter->update($table, array('children_count' => new \Zend_Db_Expr('children_count - ' . $childrenCount)), array('entity_id IN(?)' => $category->getParentIds()));
/**
* Increase children count for new category parents
*/
$adapter->update($table, array('children_count' => new \Zend_Db_Expr('children_count + ' . $childrenCount)), array('entity_id IN(?)' => $newParent->getPathIds()));
$position = $this->_processPositions($category, $newParent, $afterCategoryId);
$newPath = sprintf('%s/%s', $newParent->getPath(), $category->getId());
$newLevel = $newParent->getLevel() + 1;
$levelDisposition = $newLevel - $category->getLevel();
/**
* Update children nodes path
*/
$adapter->update($table, array('path' => new \Zend_Db_Expr('REPLACE(' . $pathField . ',' . $adapter->quote($category->getPath() . '/') . ', ' . $adapter->quote($newPath . '/') . ')'), 'level' => new \Zend_Db_Expr($levelFiled . ' + ' . $levelDisposition)), array($pathField . ' LIKE ?' => $category->getPath() . '/%'));
/**
* Update moved category data
*/
$data = array('path' => $newPath, 'level' => $newLevel, 'position' => $position, 'parent_id' => $newParent->getId());
$adapter->update($table, $data, array('entity_id = ?' => $category->getId()));
// Update category object to new data
$category->addData($data);
$category->unsetData('path_ids');
return $this;
}
示例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;
}
示例6: getParentDesignCategory
/**
* Return parent category of current category with own custom design settings
*
* @param \Magento\Catalog\Model\Category $category
* @return \Magento\Catalog\Model\Category
*/
public function getParentDesignCategory($category)
{
$pathIds = array_reverse($category->getPathIds());
$collection = clone $category->getCollection();
$collection->setMainTable($this->getMainStoreTable($category->getStoreId()))->addFieldToSelect('*')->addFieldToFilter('entity_id', ['in' => $pathIds])->addFieldToFilter('custom_use_parent_settings', [['eq' => 0], ['null' => 0]])->addFieldToFilter('level', ['neq' => 0])->setOrder('level', 'DESC')->load();
return $collection->getFirstItem();
}
示例7: getPathIds
/**
* {@inheritdoc}
*/
public function getPathIds()
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'getPathIds');
if (!$pluginInfo) {
return parent::getPathIds();
} else {
return $this->___callPlugins('getPathIds', func_get_args(), $pluginInfo);
}
}