getData('order'); if($order->getStatus() == "complete"){ $customerId = $order->getCustomerId(); $rules = Mage::getModel('salesrule/rule')->getCollection(); foreach($rules as $rule){ if($rule->getSimpleAction() == Orange35_Accumulativepromo_Model_SalesRule_Rule::ACCUMULATIVE_ACTION){ $date = Mage::getSingleton('core/date'); $orderstotalperiodModel = Mage::getModel('orange35_accumulativepromo/orderstotalperiod'); $accumulativeModel = Mage::getModel('orange35_accumulativepromo/accumulativepromo'); $accumulativeModel->load($rule->getId()); $to = $date->gmtDate("Y-m-d H:i:s", Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); $from = $date->gmtDate("Y-m-d H:i:s", date('Y-m-d H:i:s', strtotime("-" . $accumulativeModel->getData("orders_period") . " month", Mage::getModel('core/date')->timestamp(time())))); $orderstotalperiodCollection = Mage::getModel('orange35_accumulativepromo/orderstotalperiod')->getCollection() ->addFieldToFilter('customer_id', array('eq' => array($customerId))) ->addFieldToFilter('period', array('eq' => array($accumulativeModel->getData("orders_period")))); $orderstotalperiodItem = $orderstotalperiodCollection->fetchItem(); $orderCollection = Mage::getModel('sales/order')->getCollection() ->addFieldToFilter('customer_id', array('eq' => array($customerId))) ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to)) ->addFieldToFilter('status', array("in" => array('complete'))); $orders_total = 0; foreach ($orderCollection AS $order_row) { $orders_total += $order_row->getData("base_grand_total"); } if ($orderstotalperiodItem) { $items = array( 'id' => $orderstotalperiodItem->getId(), 'customer_id' => $customerId, 'period' => $accumulativeModel->getData("orders_period"), 'orders_total' => $orders_total, 'date_modified' => $date->gmtDate(), ); } else { $items = array( 'customer_id' => $customerId, 'period' => $accumulativeModel->getData("orders_period"), 'orders_total' => $orders_total, 'date_modified' => $date->gmtDate(), ); } $orderstotalperiodModel->addData($items); $orderstotalperiodModel->save(); } } } return $this; } }