当前位置: 首页>>代码示例>>PHP>>正文


PHP Category::getProductsPosition方法代码示例

本文整理汇总了PHP中Magento\Catalog\Model\Category::getProductsPosition方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::getProductsPosition方法的具体用法?PHP Category::getProductsPosition怎么用?PHP Category::getProductsPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Model\Category的用法示例。


在下文中一共展示了Category::getProductsPosition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testGetProductsPosition

 public function testGetProductsPosition()
 {
     $this->assertEquals([], $this->_model->getProductsPosition());
     $this->_model->unsetData();
     $this->_model->load(6);
     $this->assertEquals([], $this->_model->getProductsPosition());
     $this->_model->unsetData();
     $this->_model->load(4);
     $this->assertContains(1, $this->_model->getProductsPosition());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:CategoryTest.php

示例2: testGetProductsPosition

 public function testGetProductsPosition()
 {
     $this->assertEquals([], $this->_model->getProductsPosition());
     $this->_model->unsetData();
     $this->_model = $this->getCategoryByName('Category 2');
     $this->assertEquals([], $this->_model->getProductsPosition());
     $this->_model->unsetData();
     $this->_model = $this->getCategoryByName('Category 1.1.1');
     $this->assertNotEmpty($this->_model->getProductsPosition());
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:10,代码来源:CategoryTest.php

示例3: _saveCategoryProducts

 /**
  * Save category products relation
  *
  * @param \Magento\Catalog\Model\Category $category
  * @return $this
  */
 protected function _saveCategoryProducts($category)
 {
     $category->setIsChangedProductList(false);
     $id = $category->getId();
     /**
      * new category-product relationships
      */
     $products = $category->getPostedProducts();
     /**
      * Example re-save category
      */
     if ($products === null) {
         return $this;
     }
     /**
      * old category-product relationships
      */
     $oldProducts = $category->getProductsPosition();
     $insert = array_diff_key($products, $oldProducts);
     $delete = array_diff_key($oldProducts, $products);
     /**
      * Find product ids which are presented in both arrays
      * and saved before (check $oldProducts array)
      */
     $update = array_intersect_key($products, $oldProducts);
     $update = array_diff_assoc($update, $oldProducts);
     $adapter = $this->_getWriteAdapter();
     /**
      * Delete products from category
      */
     if (!empty($delete)) {
         $cond = array('product_id IN(?)' => array_keys($delete), 'category_id=?' => $id);
         $adapter->delete($this->_categoryProductTable, $cond);
     }
     /**
      * Add products to category
      */
     if (!empty($insert)) {
         $data = array();
         foreach ($insert as $productId => $position) {
             $data[] = array('category_id' => (int) $id, 'product_id' => (int) $productId, 'position' => (int) $position);
         }
         $adapter->insertMultiple($this->_categoryProductTable, $data);
     }
     /**
      * Update product positions in category
      */
     if (!empty($update)) {
         foreach ($update as $productId => $position) {
             $where = array('category_id = ?' => (int) $id, 'product_id = ?' => (int) $productId);
             $bind = array('position' => (int) $position);
             $adapter->update($this->_categoryProductTable, $bind, $where);
         }
     }
     if (!empty($insert) || !empty($delete)) {
         $productIds = array_unique(array_merge(array_keys($insert), array_keys($delete)));
         $this->_eventManager->dispatch('catalog_category_change_products', array('category' => $category, 'product_ids' => $productIds));
     }
     if (!empty($insert) || !empty($update) || !empty($delete)) {
         $category->setIsChangedProductList(true);
         /**
          * Setting affected products to category for third party engine index refresh
          */
         $productIds = array_keys($insert + $delete + $update);
         $category->setAffectedProductIds($productIds);
     }
     return $this;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:74,代码来源:Category.php

示例4: getProductsPosition

 /**
  * {@inheritdoc}
  */
 public function getProductsPosition()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getProductsPosition');
     if (!$pluginInfo) {
         return parent::getProductsPosition();
     } else {
         return $this->___callPlugins('getProductsPosition', func_get_args(), $pluginInfo);
     }
 }
开发者ID:HaonanXu,项目名称:der-snack-backup,代码行数:12,代码来源:Interceptor.php


注:本文中的Magento\Catalog\Model\Category::getProductsPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。