简体   繁体   中英

Magento Bulk update Weight of associated products

我已经创建了一个分组产品并向其添加了数量为1且权重为0的关联产品,所以当我在首页搜索中搜索此分组产品时,该产品未显示,是否有一种方法可以批量更新产品的重量?已经引用了此链接http://www.magentocommerce.com/boards/viewthread/266066/并批量更新了重量,但是搜索不起作用,但是当我从管理员后端更新了每种产品的重量时,它的工作原理拥有近100,000种产品,任何帮助将不胜感激

I feel it may be issue of reindex of data, you can go through with this answer

Magento 1.7 Import product issue

if you still have the issue than go to admin->Catalog->Attributes->Manage Attributes and click on weight to edit. On edit screen, you can set the value of 'Used in Product Listing' to 'No', if it's set to yes and reindex the data and I feel it will resolve your issue.

I've written simple script to bulk update weights of the products. I've a csv with 2 columns first column is sku and another with weights of the products to be updated. Below is the script

set_time_limit(0);

$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app('admin');
Mage::register('isSecureArea', 1);

 try{

$csv = new Varien_File_Csv();
$file = 'set_products_with_weight.csv';
$products = $csv->getData($file);
$count = 0;

$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$writeConnection = $resource->getConnection('core_write');

foreach($products as $product)
{

    $weight = (float) $product[1];

    $query = 'UPDATE catalog_product_entity_decimal set value = '.$weight.' WHERE attribute_id = 80 AND entity_id IN (SELECT entity_id FROM catalog_product_entity where sku ="'.$product[0].'")';
    $results = $writeConnection->query($query);


}

} catch(Exception $e) {

    print_r($e);

}

Where 80 is the attribute_id of weight attribute. You need to check this in database. OR you can update the query with inner join with attribute_id and filter by attribute_code=weight.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM