public function aroundGetUrlInstance(Category $category, \Closure $proceed)
 {
     if ($category->getStoreId() == 0) {
         return $proceed();
     } else {
         return $this->objectManager->create(self::FRONTEND_URL)->setStoreId($category->getStoreId());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function generate($category)
 {
     $this->category = $category;
     $storeId = $this->category->getStoreId();
     $urls = $this->isGlobalScope($storeId) ? $this->generateForGlobalScope() : $this->generateForSpecificStoreView($storeId);
     $this->category = null;
     return $urls;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function generate($category)
 {
     $this->category = $category;
     $storeId = $this->category->getStoreId();
     $urls = $this->catalogUrlRewriteHelper->isDefaultStore($storeId) ? $this->generateForDefaultStore() : $this->generateForStore($storeId);
     $this->category = null;
     return $urls;
 }
 /**
  * @magentoDataFixture Magento/Store/_files/core_fixturestore.php
  * @magentoAppIsolation enabled
  * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
  */
 public function testSetStoreIdWithNonNumericValue()
 {
     /** @var $store \Magento\Store\Model\Store */
     $store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Store\\Model\\Store');
     $store->load('fixturestore');
     $this->assertNotEquals($this->_model->getStoreId(), $store->getId());
     $this->_model->setStoreId('fixturestore');
     $this->assertEquals($this->_model->getStoreId(), $store->getId());
 }
 /**
  * Generate url rewrites for products assigned to category
  *
  * @param Category $category
  * @return array
  */
 public function generateProductUrlRewrites(Category $category)
 {
     $this->isSkippedProduct = [];
     $saveRewriteHistory = $category->getData('save_rewrites_history');
     $storeId = $category->getStoreId();
     $productUrls = [];
     if ($category->getAffectedProductIds()) {
         $this->isSkippedProduct = $category->getAffectedProductIds();
         $collection = $this->productCollectionFactory->create()->setStoreId($storeId)->addIdFilter($category->getAffectedProductIds())->addAttributeToSelect('name')->addAttributeToSelect('url_key')->addAttributeToSelect('url_path');
         foreach ($collection as $product) {
             $product->setStoreId($storeId);
             $product->setData('save_rewrites_history', $saveRewriteHistory);
             $productUrls = array_merge($productUrls, $this->productUrlRewriteGenerator->generate($product));
         }
     } else {
         $productUrls = array_merge($productUrls, $this->getCategoryProductsUrlRewrites($category, $storeId, $saveRewriteHistory));
     }
     foreach ($this->childrenCategoriesProvider->getChildren($category, true) as $childCategory) {
         $productUrls = array_merge($productUrls, $this->getCategoryProductsUrlRewrites($childCategory, $storeId, $saveRewriteHistory));
     }
     return $productUrls;
 }
 /**
  * Get category url path
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param int $storeId
  * @return string
  */
 public function getUrlPathWithSuffix($category, $storeId = null)
 {
     if ($storeId === null) {
         $storeId = $category->getStoreId();
     }
     return $this->getUrlPath($category) . $this->getCategoryUrlSuffix($storeId);
 }
Example #7
0
 /**
  * Return children ids of category
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param boolean $recursive
  * @return array
  */
 public function getChildren($category, $recursive = true)
 {
     $attributeId = (int) $this->_getIsActiveAttributeId();
     $backendTable = $this->getTable(array($this->getEntityTablePrefix(), 'int'));
     $adapter = $this->_getReadAdapter();
     $checkSql = $adapter->getCheckSql('c.value_id > 0', 'c.value', 'd.value');
     $bind = array('attribute_id' => $attributeId, 'store_id' => $category->getStoreId(), 'scope' => 1, 'c_path' => $category->getPath() . '/%');
     $select = $this->_getReadAdapter()->select()->from(array('m' => $this->getEntityTable()), 'entity_id')->joinLeft(array('d' => $backendTable), 'd.attribute_id = :attribute_id AND d.store_id = 0 AND d.entity_id = m.entity_id', array())->joinLeft(array('c' => $backendTable), 'c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.entity_id = m.entity_id', array())->where($checkSql . ' = :scope')->where($adapter->quoteIdentifier('path') . ' LIKE :c_path');
     if (!$recursive) {
         $select->where($adapter->quoteIdentifier('level') . ' <= :c_level');
         $bind['c_level'] = $category->getLevel() + 1;
     }
     return $adapter->fetchCol($select, $bind);
 }
Example #8
0
 /**
  * Return children ids of category
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param boolean $recursive
  * @return array
  */
 public function getChildren($category, $recursive = true)
 {
     $linkField = $this->getLinkField();
     $attributeId = $this->getIsActiveAttributeId();
     $backendTable = $this->getTable([$this->getEntityTablePrefix(), 'int']);
     $connection = $this->getConnection();
     $checkSql = $connection->getCheckSql('c.value_id > 0', 'c.value', 'd.value');
     $linkField = $this->getLinkField();
     $bind = ['attribute_id' => $attributeId, 'store_id' => $category->getStoreId(), 'scope' => 1, 'c_path' => $category->getPath() . '/%'];
     $select = $this->getConnection()->select()->from(['m' => $this->getEntityTable()], 'entity_id')->joinLeft(['d' => $backendTable], "d.attribute_id = :attribute_id AND d.store_id = 0 AND d.{$linkField} = m.{$linkField}", [])->joinLeft(['c' => $backendTable], "c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.{$linkField} = m.{$linkField}", [])->where($checkSql . ' = :scope')->where($connection->quoteIdentifier('path') . ' LIKE :c_path');
     if (!$recursive) {
         $select->where($connection->quoteIdentifier('level') . ' <= :c_level');
         $bind['c_level'] = $category->getLevel() + 1;
     }
     return $connection->fetchCol($select, $bind);
 }
 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;
 }
Example #10
0
 /**
  * Return children ids of category
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param bool $recursive
  * @param bool $isActive
  * @return array
  */
 public function getChildren($category, $recursive = true, $isActive = true)
 {
     $select = $this->_getReadAdapter()->select()->from($this->getMainStoreTable($category->getStoreId()), 'entity_id')->where('path LIKE ?', "{$category->getPath()}/%");
     if (!$recursive) {
         $select->where('level <= ?', $category->getLevel() + 1);
     }
     if ($isActive) {
         $select->where('is_active = ?', '1');
     }
     $_categories = $this->_getReadAdapter()->fetchAll($select);
     $categoriesIds = [];
     foreach ($_categories as $_category) {
         $categoriesIds[] = $_category['entity_id'];
     }
     return $categoriesIds;
 }
Example #11
0
 /**
  * Return a mini-breadcrumb for a category
  *
  * @param \Magento\Catalog\Model\Category $category The category
  *
  * @return array
  */
 private function getCategoryBreadcrumb(\Magento\Catalog\Model\Category $category)
 {
     $path = $category->getPath();
     $rawPath = explode('/', $path);
     // First occurence is root category (1), second is root category of store.
     $rawPath = array_slice($rawPath, 2);
     // Last occurence is the category displayed.
     array_pop($rawPath);
     $breadcrumb = [];
     foreach ($rawPath as $categoryId) {
         $breadcrumb[] = html_entity_decode($this->getCategoryNameById($categoryId, $category->getStoreId()));
     }
     return $breadcrumb;
 }
Example #12
0
 /**
  * Get data for saving code model
  *
  * @return array
  */
 protected function _getCodeData()
 {
     return ['entity_type' => \Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_CATEGORY, 'entity_id' => $this->_category->getId(), 'store_id' => $this->_category->getStoreId(), 'experiment_script' => $this->_params['experiment_script']];
 }
Example #13
0
 /**
  * Generate category url key path
  *
  * @param \Magento\Catalog\Model\Category $category
  * @return string
  */
 public function generateCategoryUrlKeyPath($category)
 {
     $parentPath = $this->categoryHelper->getCategoryUrlPath('', true, $category->getStoreId());
     $urlKey = $category->getUrlKey() == '' ? $category->formatUrlKey($category->getName()) : $category->formatUrlKey($category->getUrlKey());
     return $parentPath . $urlKey;
 }
 /**
  * Add use default settings
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param array $categoryData
  * @return array
  */
 protected function addUseDefaultSettings($category, $categoryData)
 {
     if ($category->getExistsStoreValueFlag('url_key') || $category->getStoreId() === Store::DEFAULT_STORE_ID) {
         $categoryData['use_default']['url_key'] = false;
     } else {
         $categoryData['use_default']['url_key'] = true;
     }
     return $categoryData;
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function getStoreId()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getStoreId');
     if (!$pluginInfo) {
         return parent::getStoreId();
     } else {
         return $this->___callPlugins('getStoreId', func_get_args(), $pluginInfo);
     }
 }
 /**
  * Retrieve the category product sorter load URL.
  *
  * @param Category $category Category.
  *
  * @return string
  */
 private function getProductSorterLoadUrl(Category $category)
 {
     $storeId = $category->getStoreId();
     if ($storeId === 0) {
         $defaultStoreId = $this->storeManager->getDefaultStoreView()->getId();
         $storeId = current(array_filter($category->getStoreIds()));
         if (in_array($defaultStoreId, $category->getStoreIds())) {
             $storeId = $defaultStoreId;
         }
     }
     $urlParams = ['ajax' => true, 'store' => $storeId];
     return $this->urlBuilder->getUrl('virtualcategory/category_virtual/preview', $urlParams);
 }