예제 #1
0
 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
0
 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
0
 /**
  * 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
0
 /**
  * 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;
 }
 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
0
 /**
  * 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
0
 /**
  * {@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);
     }
 }