protected function setUp() { $this->_category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Category'); $this->_category->load(5); $layer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Layer\\Category', ['data' => ['current_category' => $this->_category]]); $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Layer\\Filter\\Category', ['layer' => $layer]); }
/** * Get Category from request * * @return Category */ protected function _getCategory() { if (!$this->_category) { $this->_category = $this->_objectManager->create('Magento\\Catalog\\Model\\Category'); $categoryId = (int) $this->getRequest()->getParam('category', 0); if (!$categoryId && $this->_getUrlRewrite()->getId()) { $categoryId = $this->_getUrlRewrite()->getCategoryId(); } if ($categoryId) { $this->_category->load($categoryId); } } return $this->_category; }
public function testIsInRootCategoryList() { $this->assertFalse($this->_model->isInRootCategoryList()); $this->_model->unsetData(); $this->_model->load(3); $this->assertTrue($this->_model->isInRootCategoryList()); }
public function testGetProductCount() { $this->_model->load(6); $this->assertEquals(0, $this->_model->getProductCount()); $this->_model->setData(array()); $this->_model->load(3); $this->assertEquals(1, $this->_model->getProductCount()); }
/** * Get Category from request * * @return Category */ protected function _getCategory() { if (!$this->_category) { $this->_category = $this->_objectManager->create('Magento\\Catalog\\Model\\Category'); $categoryId = (int) $this->getRequest()->getParam('category', 0); $urlRewrite = $this->_getUrlRewrite(); if (!$categoryId && $urlRewrite->getId()) { $metaData = $urlRewrite->getMetadata(); if ($urlRewrite->getEntityType() === self::ENTITY_TYPE_CATEGORY) { $categoryId = $urlRewrite->getEntityId(); } elseif (!empty($metaData['category_id'])) { $categoryId = $metaData['category_id']; } } if ($categoryId) { $this->_category->load($categoryId); } } return $this->_category; }
/** * @param $params * @return \stdClass */ public function getFiltersValues($params) { $filters = new \stdClass(); if (isset($params['cat'])) { $filters->filter_hc_category = ''; $category = $this->catalogCategory->load($params['cat']); $categories = explode('/', $category->getPath()); foreach ($categories as $cat) { $name = $category = $this->catalogCategory->load($cat)->getName(); if (strpos($name, '/') !== false) { $name = str_replace('/', '\\/', $name); } $filters->filter_hc_category .= '/' . $name; } unset($params['cat']); } if (isset($params['price'])) { $prices = explode('-', $params['price']); if (!empty($prices[0])) { $filters->filter_from_incl_price = $prices[0]; } if (!empty($prices[1])) { $filters->filter_to_incl_price = $prices[1]; } unset($params['price']); } if (isset($params)) { $list = $this->factory->create(); $list->load(); foreach ($params as $param => $values) { $getAttribute = null; foreach ($list as $cat) { if ($param == $cat->getName()) { $getAttribute = $cat; } } if ($getAttribute !== null) { $values = html_entity_decode($values); preg_match_all('!\\d+!', $values, $matches); if (is_array($matches[0])) { $attrValues = array(); $paramName = 'filter_' . $param; foreach ($matches[0] as $id) { $attribute = $attribute = $getAttribute->getSource()->getOptionText($id); $attrValues[] = $attribute; } $filters->paramName = $attrValues; } } } } return $filters; }
/** * Get Category from request * * @return Category */ private function _getCategory() { if (!$this->_category) { $this->_category = $this->_objectManager->create('Magento\\Catalog\\Model\\Category'); $categoryId = (int) $this->getRequest()->getParam('category', 0); if (!$categoryId && $this->_getUrlRewrite()->getId() && $this->_getUrlRewrite()->getEntityType() === self::ENTITY_TYPE_CATEGORY) { $categoryId = $this->_getUrlRewrite()->getEntityId(); } if ($categoryId) { $this->_category->load($categoryId); } } return $this->_category; }
/** * @magentoAppArea adminhtml */ public function testDeleteChildren() { $this->_model->unsetData(); $this->_model->load(4); $this->_model->setSkipDeleteChildren(true); $this->_model->delete(); $this->_model->unsetData(); $this->_model->load(5); $this->assertEquals($this->_model->getId(), 5); $this->_model->unsetData(); $this->_model->load(3); $this->assertEquals($this->_model->getId(), 3); $this->_model->delete(); $this->_model->unsetData(); $this->_model->load(5); $this->assertEquals($this->_model->getId(), null); }
/** * @magentoDataFixture Magento/Catalog/_files/category_with_position.php */ public function testSaveCategoryWithPosition() { $category = $this->_model->load('444'); $this->assertEquals('5', $category->getPosition()); }
/** * {@inheritdoc} */ public function load($modelId, $field = null) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'load'); if (!$pluginInfo) { return parent::load($modelId, $field); } else { return $this->___callPlugins('load', func_get_args(), $pluginInfo); } }