Example #1
0
 public static function collectDay($date)
 {
     $instance = new self();
     $quoteCollection = Mage::getModel('Mage_Reports_Model_Mysql4_Quote_Collection')->prepareForAbandonedReport(0);
     $quoteCollection->getSelect()->where('`main_table`.`updated_at` BETWEEN \'' . $date . '\' AND \'' . $date . '\' + INTERVAL 1 DAY');
     foreach ($quoteCollection as $quote) {
         $instance->load($quote->getEntityId(), 'quote_id');
         $instance->setQuoteId($quote->getEntityId());
         $instance->setCartPrice($quote->getBaseGrandTotal());
         $instance->setCartAbandonDate($quote->getUpdatedAt());
         $items = array();
         foreach ($quote->getAllItems() as $item) {
             if ($item->getProductType() == 'simple') {
                 $items[$item->getProductId()] = $item->getQty();
             }
         }
         $instance->setCartItems(serialize($items));
         $historyCollection = Mage::getModel('adjcartalert/history')->getCollection();
         $historyCollection->addFieldToFilter('quote_id', $quote->getEntityId())->setOrder('sent_at', 'DESC');
         $history = $historyCollection->getFirstItem();
         $instance->setAlertNumber($instance->_followupArray[$history->getFollowUp()]);
         $instance->setAlertDate($history->getSheduledAt());
         $instance->setRecoveryDate($history->getRecoveredAt());
         $orderCollection = Mage::getModel('sales/order')->getCollection();
         $order = $orderCollection->addFieldToFilter('quote_id', $quote->getEntityId())->getFirstItem();
         if ($order->getId()) {
             $instance->setOrderDate($order->getCreatedAt());
             $instance->setOrderPrice($order->getBaseGrandTotal());
             $items = array();
             foreach ($order->getAllItems() as $item) {
                 if ($item->getProductType() == 'simple') {
                     $items[$item->getProductId()] = $item->getQtyOrdered();
                 }
             }
             $instance->setOrderItems(serialize($items));
             $instance->setOrderCouponUsed($order->getCouponCode());
         }
         $instance->save();
     }
 }