/** * Process positions of old parent category children and new parent category children. * Get position for moved category * * @param \Magento\Catalog\Model\Category $category * @param \Magento\Catalog\Model\Category $newParent * @param null|int $afterCategoryId * @return int */ protected function _processPositions($category, $newParent, $afterCategoryId) { $table = $this->getEntityTable(); $adapter = $this->_getWriteAdapter(); $positionField = $adapter->quoteIdentifier('position'); $bind = array('position' => new \Zend_Db_Expr($positionField . ' - 1')); $where = array('parent_id = ?' => $category->getParentId(), $positionField . ' > ?' => $category->getPosition()); $adapter->update($table, $bind, $where); /** * Prepare position value */ if ($afterCategoryId) { $select = $adapter->select()->from($table, 'position')->where('entity_id = :entity_id'); $position = $adapter->fetchOne($select, array('entity_id' => $afterCategoryId)); $position += 1; } else { $position = 1; } $bind = array('position' => new \Zend_Db_Expr($positionField . ' + 1')); $where = array('parent_id = ?' => $newParent->getId(), $positionField . ' >= ?' => $position); $adapter->update($table, $bind, $where); return $position; }
/** * {@inheritdoc} */ public function getPosition() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getPosition'); if (!$pluginInfo) { return parent::getPosition(); } else { return $this->___callPlugins('getPosition', func_get_args(), $pluginInfo); } }