Esempio n. 1
0
 public function removeTotals(AW_Giftcard_Model_Giftcard $giftcardModel)
 {
     $write = $this->_getWriteAdapter();
     $write->query("DELETE FROM {$this->getTable('aw_giftcard/history')} " . "WHERE giftcard_id = {$giftcardModel->getId()}");
     $write->query("DELETE FROM {$this->getTable('aw_giftcard/quote_giftcard')} " . "WHERE giftcard_id = {$giftcardModel->getId()}");
     $write->query("DELETE FROM {$this->getTable('aw_giftcard/order_invoice_giftcard')} " . "WHERE giftcard_id = {$giftcardModel->getId()}");
     $write->query("DELETE FROM {$this->getTable('aw_giftcard/order_creditmemo_giftcard')} " . "WHERE giftcard_id = {$giftcardModel->getId()}");
     return $this;
 }
Esempio n. 2
0
 public function addCardToQuote(AW_Giftcard_Model_Giftcard $giftcard, $quote = null)
 {
     if (null === $quote) {
         $quote = $this->getQuote();
     }
     if ($giftcard->isValidForRedeem($quote->getStoreId())) {
         $_collection = Mage::getModel('aw_giftcard/quote_giftcard')->getCollection();
         $_collection->setFilterByQuoteId($quote->getId())->setFilterByGiftcardId($giftcard->getId());
         if ($_collection->getSize() > 0) {
             throw new Exception('This gift card is already in the quote');
         }
         Mage::getModel('aw_giftcard/quote_giftcard')->setQuoteEntityId($quote->getId())->setGiftcardId($giftcard->getId())->save();
     }
     return $this;
 }
Esempio n. 3
0
 public function registerAction($actionType, AW_Giftcard_Model_Giftcard $giftcardModel)
 {
     $info = array('message_type' => AW_Giftcard_Model_Source_Giftcard_History_Action::BY_ADMIN_MESSAGE_VALUE, 'message_data' => $this->_getCurrentAdminUserName());
     if (null !== $giftcardModel->getOrder()) {
         $info = array('message_type' => AW_Giftcard_Model_Source_Giftcard_History_Action::BY_ORDER_MESSAGE_VALUE, 'message_data' => $giftcardModel->getOrder()->getIncrementId());
     }
     if (null !== $giftcardModel->getCreditmemo()) {
         $orderIncrementId = $giftcardModel->getCreditmemo()->getIncrementId();
         if ($giftcardModel->getCreditmemo() instanceof Mage_Sales_Model_Order_Creditmemo) {
             $orderIncrementId = $giftcardModel->getCreditmemo()->getOrder()->getIncrementId();
         }
         $info = array('message_type' => AW_Giftcard_Model_Source_Giftcard_History_Action::BY_CREDITMEMO_MESSAGE_VALUE, 'message_data' => $orderIncrementId);
     }
     $_balanceDelta = $giftcardModel->getBalance();
     if (!$giftcardModel->getIsNew() && null !== $giftcardModel->getOrigData('balance')) {
         $_balanceDelta = $giftcardModel->getBalance() - $giftcardModel->getOrigData('balance');
     }
     $this->setGiftcardId($giftcardModel->getId())->setAction($actionType)->setBalanceDelta($_balanceDelta)->setBalanceAmount($giftcardModel->getBalance())->setAdditionalInfo($info)->save();
     return $this;
 }