php - 使用 Magento 重新索引刚刚以编程方式更改的产品

标签 php mysql magento indexing magmi

我的 Magento 商店中有超过 130.000 种产品。即使我安装了 Dn'D Patch Index URL (顺便说一句,这节省了很多时间,例如:只需 10 分钟的重新索引而不是大约 4 小时)当我只添加或更改两个产品时,通过 Magento 后端界面重新索引所有内容需要花费很多时间通过我的 PHP 文件。

是否可以仅为添加/更改的产品重新索引所有内容(搜索、价格、库存等)?我用 Magmi - DataPump 添加/更改它们工具。我的 PHP 代码如下所示:

$in=array();
$in[]= 'magmi';
$in[]= 'magmi/inc';
$in[]= 'magmi/integration/inc';
$in[]= 'magmi/engines';
$inpath="";
foreach ($in as $i){
    $inpath .= $i .':';
}
$inpath .= '.';
set_include_path($inpath);

require_once("magmi_datapump.php");    // call Datapump

$dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport");
$dp->beginImportSession("default","create");        // default- name of profile ,  create - we want to create and update items

$row = 0;
$handle = fopen("data.csv", "r");
while (($item = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $row++;
    if($row > 0 && $row < 135000){
    $newProductData = array(
            'name'          => (string) $item[1]." ".$item[3],        // name
            'sku'           => (string) $item[1],        // sku     
            'price'         => (real) $item[4],             // price
            'store'         => 'admin',            
            'description'   => (string) $item[2]."\n".$item[3]."\nHerstellerteilenummer: ".$item[1],        // full description
            'short_description' => (string) $item[2]."\n".$item[3]."\nHerstellerteilenummer: ".$item[1],    // short description
            'category_ids'    => '4',                // ID of categories
            'tax_class_id'  => '1',                    // tax class id (check your ids)
            'manufacturer'    => (string) $item[2],        // manufacturer
            'attribute_set' => 'Default',
            'weight'        => (string) "0",
            'use_config_manage_stock'   => 0
    );

    $newProductData['image']='+'.(string) '/media/catalog/product/placeholder/high/'.$item[2].'.png';        // + show picture, - dont show picture
    $newProductData['small_image']='+'.(string) '/media/catalog/product/placeholder/small/'.$item[2].'.png';            // small img
    $newProductData['thumbnail']='+'.(string) '/media/catalog/product/placeholder/thumb/'.$item[2].'.png';            // thumbnail
    $dp->ingest($newProductData);
    print_r($newProductData);
    echo "PRODUCT NR: " . $row;
    echo '' . ' mem:'.memory_get_usage() .  " ... Done! <br />\n";            //memory usage check
    $newProductData=null;    //clear memory
    unset($newProductData); //clear memory
    }
}

unset($item);

$dp->endImportSession();

最佳答案

“重新索引”是指在表上重新创建 MySQL 索引吗?如果是这样,就没有必要这样做了。索引是动态维护的。

关于php - 使用 Magento 重新索引刚刚以编程方式更改的产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32590238/

相关文章:

PHP:将MySQL结果排序为多维数组

mysql - 使用 3 个表和联接删除其他记录中包含字符串的记录

magento - 清除 Magento 缓存

magento - 仅选择Magento中的特定字段

mysql - 合并 MySQL 中的 2 个表和一些重复数据

php - 检查 Magento 产品是否是可配置产品的子产品

php - 在 PHP 代码的 div 声明中插入两个类之一

php - 如何在php中转换这种日期格式?

php - 选择表中的最后一条记录

php - 如何通过映射3个表在mysql中创建 View ?