magento批量修改价格

本文介绍了一段用于Magento系统的PHP脚本,该脚本能够批量调整特定产品的成本、价格及特价。通过数据库查询筛选出符合条件的产品,并根据成本价进行价格调整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?php
	require_once 'app/Mage.php';
	//echo phpinfo();exit;
	set_time_limit(0);
	Mage::app('default');
	$read = Mage::getSingleton('core/resource')->getConnection('core_read');
	$row = $read->fetchAll("select p.`entity_id` from `catalog_product_entity` as p, `catalog_product_entity_decimal` as d where p.`entity_id` = d.`entity_id` and d.`attribute_id` =79 and d.`value` not in (0,868,444)");
	//$products = Mage::getModel('catalog/category')->load(75)->getProductCollection();
	foreach($row as $val)
	{
		$product = Mage::getModel('catalog/product')->load($val['entity_id']);
		$cost = $product->getCost();
		$price = $product->getPrice();
		$special_price = $product->getSpecialPrice();
		
		if(!empty($cost))
		{
			$cost = $cost/6.1;
			//echo $product->getId() . '----';

			if(!empty($special_price)){
				//$special_price = $special_price + 1.5;
				//$product->setData('special_price', $special_price);
				if($cost >= $special_price){
					$price = $cost + 15/6.1;
					$special_price = $cost + 10/6.1;
					$product->setData('price', $price);
					$product->setData('special_price', $special_price);
					echo $product->getId() . '----' . $special_price . 's----' . $cost."<br>";
				}
			}else{
				if($cost >= $price){
					$price = $cost + 10/6.1;
					$product->setData('price', $price);
					echo $product->getId() . '----' . $price . 'p----' . $cost."<br>";
				}
			}

			//$price = $price + 1.5;
			
			//$product->setData('price', $price);
			$product->save();
			//exit;
		}
	}
	
?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值