change order status for specific product after place order use event

本文介绍了一个Magento扩展模块,该模块会在包含特定属性产品的订单完成后自动将订单状态设置为'new',并记录一条状态变更历史。

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

<global>
 <events>
        <sales_order_place_after>
            <observers>
                <sales_order_place_after_observer_change_status>
                    <type>singleton</type>
                    <class>mysales/observer</class>
                    <method>change_status</method>
                </sales_order_place_after_observer_change_status>
            </observers>
        </sales_order_place_after>
    </events>

 

<?php 
class Bysoft_Mysales_Model_Observer {
	public function change_status($observer) {
		$order = $observer->getEvent()->getOrder();
		$ordered_items = $order->getAllItems();
		$attr_ids = array();
		$attr_ids[] = $this->attributeValueExists('checkout_process','Custom products');
		$attr_ids[] = $this->attributeValueExists('checkout_process','Global sourcing commodities/pricing');
		
		foreach($ordered_items as $item){
			$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $item->getSku());
			if (in_array($product->getData('checkout_process') , $attr_ids)) {
				
				$order->setData('state', 'new');
				$order->setStatus('new');
				$history = $order->addStatusHistoryComment('New Order For Custom and Global Products.', false);
				$history->setIsCustomerNotified(false);
				$order->save();
				return;
			}
		}
	}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值