'New', self::STATUS_ORDER_PACKED => 'Packed', self::STATUS_ORDER_SENT => 'Sent', self::STATUS_ORDER_CLOSED => 'Closed' ); protected $_paidStatuses = array( self::STATUS_PAID_YES => 'Yes', self::STATUS_PAID_NO => 'No' ); protected $_periodVariations = array( self::FILTER_PERIOD_WEEK => 'last week', self::FILTER_PERIOD_MONTH => 'last month', self::FILTER_PERIOD_3_MONTH => 'last 3 months', self::FILTER_PERIOD_6_MONTH => 'last 6 months', self::FILTER_PERIOD_YEAR => 'last year' ); protected $_hasFilter = true; protected function _getFromColumns() { $delivery = 'IF (' . ' `' . $this->_tableAlias . '`.`shippingServiceCodeTitle` = "", ' . ' `' . $this->_tableAlias . '`.`shippingNameTitle`, ' . ' CONCAT_WS(' . ' "/", ' . ' `' . $this->_tableAlias . '`.`shippingNameTitle`, ' . ' `' . $this->_tableAlias . '`.`shippingServiceCodeTitle`' . ' )' . ')'; $columns = array( '*', 'submitted' => new Zend_Db_Expr('UNIX_TIMESTAMP(`' . $this->_tableAlias . '`.`added`)'), 'delivery' => new Zend_Db_Expr($delivery) ); return $columns; } protected function _prepareRow(array &$row) { $row['paidTitle'] = $this->_paidStatuses[$row['paid']]; $row['statusTitle'] = $this->_orderStatuses[$row['status']]; return parent::_prepareRow($row); } protected function _filter(Zend_Db_Select $select) { /** filter by order status */ if (isset($this->_filter['status']) && array_key_exists($this->_filter['status'], $this->getOrderStatuses()) ) { $select->where('`' . $this->_tableAlias . '`.`status` = ?', $this->_filter['status']); } /** filter by period */ if (isset($this->_filter['period']) && array_key_exists($this->_filter['period'], $this->getPeriodVariations()) ) { $sqlPeriod = strtoupper(str_replace('_', ' ', $this->_filter['period'])); $select->where('`' . $this->_tableAlias . '`.`added` >= DATE_SUB(CURDATE(), INTERVAL ' . $sqlPeriod . ')'); } /** filter by order paid */ if (isset($this->_filter['paid']) && array_key_exists($this->_filter['paid'], $this->getPaidStatuses()) ) { $select->where('`' . $this->_tableAlias . '`.`paid` = ?', $this->_filter['paid']); } $select->where("`{$this->_tableAlias}`.`enabled` = 'y'"); return $this; } public function getListSelect() { if (null === $this->_select) { parent::getListSelect(); $this->_select->join( $this->_getPair('Cart'), '`Cart`.`transactionId` = `' . $this->_tableAlias . '`.`id`', array('userId') ); } return $this->_select; } protected function _getFromDbSelect($primaryKey) { $select = parent::_getFromDbSelect($primaryKey); $select->join( $this->_getPair('Cart'), '`Cart`.`transactionId` = `' . $this->_tableAlias . '`.`id`', array('userId', 'cartId' => 'id') ); $select->joinLeft( $this->_getPair('CartItemGiftCard'), '`CartItemGiftCard`.`cartId` = `Cart`.`id`', array('giftCardPrice' => 'cardValue') ); $select->joinLeft( $this->_getPair('CartItemPromo'), '`CartItemPromo`.`cartId` = `Cart`.`id`', array('promoProductId' => 'productId', 'promoValue' => 'value', 'promoType' => 'type') ); $select->joinLeft( $this->_getPair('DPromoType'), '`DPromoType`.`id` = `CartItemPromo`.`type`', array('promoTypeTitle' => 'title') ); return $select; } protected function _addDependenciesFromDb(array &$data) { $data['statusTitle'] = $this->_orderStatuses[$data['status']]; $data['paidTitle'] = $this->_paidStatuses[$data['paid']]; $checkoutFormServicePayment = new App_ECommerce_Checkout_Form_Service_Payment(); $paymentTypes = $checkoutFormServicePayment->getPaymentType(); $data['paymentTypeTitle'] = Qs_Array::get($paymentTypes, $data['paymentType']); $cartData = $this->_getCartData($data['cartId']); $data['accessCode'] = $cartData['accessCode']; $data['cart'] = $cartData['list']; return $this; } protected function _getCartData($cartId) { $cartObj = new App_ECommerce_Cart_Obj(array('primaryKey' => $cartId)); $data = $cartObj->getData(); $list = $cartObj->getList(); $list = $this->_prepareCart($list); $data['list'] = $list; return $data; } protected function _prepareCart($list) { foreach ($list as &$item) { $item['priceRound'] = Zend_Locale_Math::round($item['price'], 2); $item['rowTotalRound'] = Zend_Locale_Math::round($item['rowTotal'], 2); } return $list; } public function updateOrderPayment($data) { if (!empty($data['invoice']) && !empty($data['transactionId'])) { $this->_getTable('Transaction')->updateByKey( array('paid' => 'y', 'enabled' => 'y'), $data['transactionId'] ); //send notification to user about paid order $transactionData = $this->setPrimaryKey($data['transactionId'])->clearData()->getData(); App_ECommerce_Order_MailAdapter::sendUserNotification( array('orderId' => $transactionData['id'], 'billingEmail' => $transactionData['billingEmail']), 'PaidStatusYes' ); } return $this; } public function verifyOrderPayment($data) { $transactionId = $data['transactionId']; $result = false; if (!empty($transactionId)) { $transactionData = $this->_getTable('Transaction')->fetchRow(array('id = ?' => $transactionId)); if ($transactionData && $transactionData->paid != 'y') { $result = ($transactionData->total == $data['total']); } } return $result; } public function getOrderStatuses() { return $this->_orderStatuses; } public function getOrderStatusTitle($orderStatus) { return $this->_orderStatuses[$orderStatus]; } public function getPaidStatuses() { return $this->_paidStatuses; } public function getPaidStatusTitle($paidStatus) { return $this->_paidStatuses[$paidStatus]; } public function getPeriodVariations() { return $this->_periodVariations; } public function getObjectInfo() { $data = (array) $this->getData(); if (!empty($data) && !array_key_exists('id', $data)) { $this->clearData(); } return parent::getObjectInfo(); } }