Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento 是否有Magmi插件可以删除CSV文件中没有的产品?_Magento_Magmi - Fatal编程技术网

Magento 是否有Magmi插件可以删除CSV文件中没有的产品?

Magento 是否有Magmi插件可以删除CSV文件中没有的产品?,magento,magmi,Magento,Magmi,我必须添加此功能,并且在编写插件之前,我想知道是否存在此类插件。我认为最好是肯定删除,而不是通过省略删除。调整转换适配器以分析列(例如“已删除”)并将\u isDeleted属性设置为true,应该很简单。这将导致产品在保存时被删除 参考Mage\u Core\u Model\u Abstract和Varien\u Object我已经用内置的产品deleter尝试过了,但效果并不理想。它会删除旧产品,但当它再次添加它们时,会增加商品号,因此在几次导入后,您就有了商品号1xxx 如果我只有从CSV

我必须添加此功能,并且在编写插件之前,我想知道是否存在此类插件。

我认为最好是肯定删除,而不是通过省略删除。调整转换适配器以分析列(例如“已删除”)并将
\u isDeleted
属性设置为
true
,应该很简单。这将导致产品在保存时被删除


参考
Mage\u Core\u Model\u Abstract
Varien\u Object

我已经用内置的产品deleter尝试过了,但效果并不理想。它会删除旧产品,但当它再次添加它们时,会增加商品号,因此在几次导入后,您就有了商品号1xxx

如果我只有从CSV导入的产品,而没有“始终”存在的产品,我实际上会在magmi之前使用php脚本删除所有产品:

    <?php

    $mysqli = new mysqli("localhost", "dbuser", "dbpassword", "db");

    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }



    $query = "

    SET FOREIGN_KEY_CHECKS = 0;

    TRUNCATE TABLE `catalog_product_bundle_price_index`;
    TRUNCATE TABLE `catalog_product_bundle_selection`;
    TRUNCATE TABLE `catalog_product_bundle_selection_price`;
    TRUNCATE TABLE `catalog_product_bundle_option_value`;
    TRUNCATE TABLE `catalog_product_bundle_option`;
    TRUNCATE TABLE `catalog_product_entity_datetime`;
    TRUNCATE TABLE `catalog_product_entity_decimal`;
    TRUNCATE TABLE `catalog_product_entity_gallery`;
    TRUNCATE TABLE `catalog_product_entity_group_price`;
    TRUNCATE TABLE `catalog_product_entity_int`;
    TRUNCATE TABLE `catalog_product_entity_media_gallery`;
    TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
    TRUNCATE TABLE `catalog_product_entity_text`;
    TRUNCATE TABLE `catalog_product_entity_tier_price`;
    TRUNCATE TABLE `catalog_product_entity_varchar`;
    TRUNCATE TABLE `catalog_product_flat_1`;
    TRUNCATE TABLE `catalog_product_link`;
    TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
    TRUNCATE TABLE `catalog_product_link_attribute_int`;
    TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
    TRUNCATE TABLE `catalog_product_option`;
    TRUNCATE TABLE `catalog_product_option_price`;
    TRUNCATE TABLE `catalog_product_option_title`;
    TRUNCATE TABLE `catalog_product_option_type_price`;
    TRUNCATE TABLE `catalog_product_option_type_title`;
    TRUNCATE TABLE `catalog_product_option_type_value`;
    TRUNCATE TABLE `catalog_product_super_attribute_label`;
    TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
    TRUNCATE TABLE `catalog_product_super_attribute`;
    TRUNCATE TABLE `catalog_product_super_link`;
    TRUNCATE TABLE `catalog_product_enabled_index`;
    TRUNCATE TABLE `catalog_product_website`;
    TRUNCATE TABLE `catalog_category_product_index`;
    TRUNCATE TABLE `catalog_product_index_price`;
    TRUNCATE TABLE `catalog_product_index_eav`;
    TRUNCATE TABLE `catalog_category_product`;
    TRUNCATE TABLE `catalog_product_index_eav_idx`;
    TRUNCATE TABLE `catalog_product_entity`;
    TRUNCATE TABLE `catalog_product_relation`;
    TRUNCATE TABLE `catalog_product_index_price_idx`;
    TRUNCATE TABLE `catalog_product_index_website`;
    TRUNCATE TABLE `cataloginventory_stock_item`;
    TRUNCATE TABLE `cataloginventory_stock_status`;
    TRUNCATE TABLE  `core_url_rewrite`;

    SET FOREIGN_KEY_CHECKS = 1; 
    ";

   $results = mysqli_multi_query($mysqli,$query);

   $mysqli->close();


   ?>


希望有帮助。

我创建了一个插件,可以禁用CSV中没有的文件。我更喜欢禁用这些项目,而不是在出现问题时实际删除它们(这不会擦除我的数据库)

  • 创建插件文件
    magmi/plugins/extra/general/itemdisabler/magmi\u itemdisabler\u plugin.php

  • 在文件中,粘贴以下内容并保存:

  • 插件代码:

    <?php
    class Magmi_ItemdisablerPlugin extends Magmi_ItemProcessor
    {
        protected $datasource_skus = array();    
    
        public function getPluginInfo()
        {
            return array("name"=>"Magmi Magento Item Disabler",
                                 "author"=>"Axel Norvell (axelnorvell.com)",
                                 "version"=>"1.0.6");
        }      
    
        public function afterImport()
        {
            $this->log("Running Item Disabler Plugin","info");
            $this->disableItems();
            return true;
        }
    
        public function getPluginParams($params)
        {
            return array();
        }
    
        public function isRunnable()
        {
            return array(true,"");
        }
    
        public function initialize($params)
        {
        }
    
        public function processItemAfterId(&$item,$params=null)
        {
            if(isset($item['sku']))
            {
                $this->datasource_skus[] = $item['sku'];
            }
        }
    
        public function disableItems()
        {
            if(count($this->datasource_skus) <= 0)
            {
                $this->log('No items were found in datasource.  Item Disabler will not run.', "info");
                return false; /* Nothing to disable */  
            }
    
            //Setup tables
            $ea     = $prefix!=""?$prefix."eav_attribute":"eav_attribute";
            $eet     = $prefix!=""?$prefix."eav_entity_type":"eav_entity_type";
            $cpe     = $prefix!=""?$prefix."catalog_product_entity":"catalog_product_entity";
            $cpei     = $prefix!=""?$prefix."catalog_product_entity_int":"catalog_product_entity_int";
    
            //Get "status" attribute_id
            $status_attr_id = "     
                SELECT ea.attribute_id FROM $ea ea
                LEFT JOIN $eet eet ON ea.entity_type_id = eet.entity_type_id
                WHERE ea.attribute_code = 'status'
                AND eet.entity_type_code = 'catalog_product'";               
            $result = $this->selectAll($status_attr_id);  
            if (count($result) == 1) {
                $attribute_id = $result[0]['attribute_id'];
            }
            unset($result);
    
            //Get all active items
            $sql = "SELECT e.sku, e.entity_id FROM $cpei i
                              INNER JOIN $cpe e ON
                              e.entity_id = i.entity_id
                              WHERE attribute_id=?
                              AND i.value = 1";
            $all_magento_items = $this->selectAll($sql, array($attribute_id));
    
            //Setup the magento_skus array for easy processing.
            $magento_skus = array();
            foreach($all_magento_items as $item)
            {
                $this->log("{$item['sku']} found in Mage", "info");
    
                $magento_skus[$item['sku']] = $item['entity_id'];
            }
    
    
            //process the array, move anything thats in the datasource.
            foreach($this->datasource_skus as $sku)
            {
                if(isset($magento_skus[$sku]))
                {
                    unset($magento_skus[$sku]);
                }
            }
    
            if(!empty($magento_skus))
            {               
                foreach($magento_skus as $sku => $id)
                {
    
                    $this->log("Disabling Item Id $id with SKU: $sku", "info"); 
                    $this->update("
                        UPDATE $cpei i
                        INNER JOIN $cpe e ON
                        e.entity_id = i.entity_id
                        SET VALUE = '2'
                        WHERE attribute_id = ?
                        AND i.value = 1
                        AND e.sku=?", array($attribute_id, $sku));
                }
            }
            else
            {
                //If the Datasource contains all Magento's items.
                $this->log('All items present in datasource.  No items to disable.', "info");       
            }
    
        }
    }
    

    我想我会提到,如果人们有一个非常大的产品列表,并且他们试图运行这个禁用程序,那么他们可能会遇到问题。我对magmi不太熟悉,但在使用cli时似乎会出现更多的错误,所以如果您发现解散不起作用,请尝试使用它进行测试。它不适合我,我把它缩小到php内存限制。我不得不更改脚本以包含ini_集(“内存限制”,“512M”);在disableItems函数中

    所以,我的现在看起来像这样

    public function disableItems()
    {
        ini_set('max_execution_time', 0);
        set_time_limit(0);
        ini_set('memory_limit','512M');
        umask(0); 
    

    我希望这能帮助任何人,如果他们对此有任何问题。我还必须让我的车在需要的时间内运行,而且一切都需要。最好在您的配置文件中设置此选项,但这是一个快速解决方案,尤其是在共享主机上。

    这里有一个Magmi插件,它完全符合您的要求:

    完全同意,您最好肯定地删除它。好消息是,玛格米有这种能力与它的。只要创建一个magmi:delete列,并在其中放入一个1,当您想删除该项时,在每次导入之前截断整个数据库有点极端,您不觉得吗?当它工作时,当他运行导入时,站点将有一段时间显示为完全空的。它还否定了更新产品带来的任何性能好处,而不是每次都重新创建产品。2个插件:missing product deleter&missing product disabler for Magmi:,它重用默认的产品删除器