Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_GiftMessage_Block_Adminhtml_Product_Helper_Form_Config
  • Mage_GiftMessage_Block_Adminhtml_Sales_Order_Create_Form
  • Mage_GiftMessage_Block_Adminhtml_Sales_Order_Create_Giftoptions
  • Mage_GiftMessage_Block_Adminhtml_Sales_Order_Create_Items
  • Mage_GiftMessage_Block_Adminhtml_Sales_Order_View_Form
  • Mage_GiftMessage_Block_Adminhtml_Sales_Order_View_Giftoptions
  • Mage_GiftMessage_Block_Adminhtml_Sales_Order_View_Items
  • Mage_GiftMessage_Block_Message_Inline
  • Mage_GiftMessage_Helper_Data
  • Mage_GiftMessage_Helper_Message
  • Mage_GiftMessage_Helper_Url
  • Mage_GiftMessage_Model_Api
  • Mage_GiftMessage_Model_Api_V2
  • Mage_GiftMessage_Model_Message
  • Mage_GiftMessage_Model_Mysql4_Message
  • Mage_GiftMessage_Model_Mysql4_Message_Collection
  • Mage_GiftMessage_Model_Mysql4_Setup
  • Mage_GiftMessage_Model_Observer
  • Mage_GiftMessage_Model_Resource_Message
  • Mage_GiftMessage_Model_Resource_Message_Collection
  • Mage_GiftMessage_Model_Resource_Setup
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_GiftMessage
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * GiftMessage api
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_GiftMessage
 32:  * @author     Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_GiftMessage_Model_Api extends Mage_Checkout_Model_Api_Resource_Product
 35: {
 36:     /**
 37:      * Return an Array of attributes.
 38:      *
 39:      * @param Array $obj
 40:      * @return Array
 41:      */
 42:     protected function _prepareData($arr)
 43:     {
 44:         if (is_array($arr)) {
 45:             return $arr;
 46:         }
 47:         return array();
 48:     }
 49: 
 50:     /**
 51:      * Raise event for setting a giftMessage.
 52:      *
 53:      * @param String $entityId
 54:      * @param Mage_Core_Controller_Request_Http $request
 55:      * @param Mage_Sales_Model_Quote $quote
 56:      * @return AssociativeArray
 57:      */
 58:     protected function _setGiftMessage($entityId, $request, $quote)
 59:     {
 60: 
 61:         /**
 62:          * Below code will catch exceptions only in DeveloperMode
 63:          * @see Mage_Core_Model_App::_callObserverMethod($object, $method, $observer)
 64:          * And result of Mage::dispatchEvent will always return an Object of Mage_Core_Model_App.
 65:          */
 66:         try {
 67:             Mage::dispatchEvent(
 68:                 'checkout_controller_onepage_save_shipping_method',
 69:                 array('request' => $request, 'quote' => $quote)
 70:             );
 71:             return array('entityId' => $entityId, 'result' => true, 'error' => '');
 72:         } catch (Exception $e) {
 73:             return array('entityId' => $entityId, 'result' => false, 'error' => $e->getMessage());
 74:         }
 75:     }
 76: 
 77:     /**
 78:      * Set GiftMessage for a Quote.
 79:      *
 80:      * @param String $quoteId
 81:      * @param AssociativeArray $giftMessage
 82:      * @param String $store
 83:      * @return AssociativeArray
 84:      */
 85:     public function setForQuote($quoteId, $giftMessage, $store = null)
 86:     {
 87:         /** @var $quote Mage_Sales_Model_Quote */
 88:         $quote = $this->_getQuote($quoteId, $store);
 89: 
 90:         $giftMessage = $this->_prepareData($giftMessage);
 91:         if (empty($giftMessage)) {
 92:             $this->_fault('giftmessage_invalid_data');
 93:         }
 94: 
 95:         $giftMessage['type'] = 'quote';
 96:         $giftMessages = array($quoteId => $giftMessage);
 97:         $request = new Mage_Core_Controller_Request_Http();
 98:         $request->setParam("giftmessage", $giftMessages);
 99: 
100:         return $this->_setGiftMessage($quote->getId(), $request, $quote);
101:     }
102: 
103:     /**
104:      * Set a GiftMessage to QuoteItem by product
105:      *
106:      * @param String $quoteId
107:      * @param Array $productsAndMessages
108:      * @param String $store
109:      * @return array
110:      */
111:     public function setForQuoteProduct($quoteId, $productsAndMessages, $store = null)
112:     {
113:         /** @var $quote Mage_Sales_Model_Quote */
114:         $quote = $this->_getQuote($quoteId, $store);
115: 
116:         $productsAndMessages = $this->_prepareData($productsAndMessages);
117:         if (empty($productsAndMessages)) {
118:             $this->_fault('invalid_data');
119:         }
120: 
121:         if (count($productsAndMessages) == 2
122:                 && isset($productsAndMessages['product'])
123:                 && isset($productsAndMessages['message'])) {
124:             $productsAndMessages = array($productsAndMessages);
125:         }
126: 
127:         $results = array();
128:         foreach ($productsAndMessages as $productAndMessage) {
129:             if (isset($productAndMessage['product']) && isset($productAndMessage['message'])) {
130:                 $product = $this->_prepareData($productAndMessage['product']);
131:                 if (empty($product)) {
132:                     $this->_fault('product_invalid_data');
133:                 }
134:                 $message = $this->_prepareData($productAndMessage['message']);
135:                 if (empty($message)) {
136:                     $this->_fault('giftmessage_invalid_data');
137:                 }
138: 
139:                 if (isset($product['product_id'])) {
140:                     $productByItem = $this->_getProduct($product['product_id'], $store, "id");
141:                 } elseif (isset($product['sku'])) {
142:                     $productByItem = $this->_getProduct($product['sku'], $store, "sku");
143:                 } else {
144:                     continue;
145:                 }
146: 
147:                 $productObj = $this->_getProductRequest($product);
148:                 $quoteItem = $this->_getQuoteItemByProduct($quote, $productByItem, $productObj);
149:                 $results[] = $this->setForQuoteItem($quoteItem->getId(), $message, $store);
150:             }
151:         }
152: 
153:         return $results;
154:     }
155: 
156:     /**
157:      * Set GiftMessage for a QuoteItem by its Id.
158:      *
159:      * @param String $quoteItemId
160:      * @param AssociativeArray $giftMessage
161:      * @param String $store
162:      * @return AssociativeArray
163:      */
164:     public function setForQuoteItem($quoteItemId, $giftMessage, $store = null)
165:     {
166:         /** @var $quote Mage_Sales_Model_Quote_Item */
167:         $quoteItem = Mage::getModel('sales/quote_item')->load($quoteItemId);
168:         if (is_null($quoteItem->getId())) {
169:             $this->_fault("quote_item_not_exists");
170:         }
171: 
172:         /** @var $quote Mage_Sales_Model_Quote */
173:         $quote = $this->_getQuote($quoteItem->getQuoteId(), $store);
174: 
175:         $giftMessage = $this->_prepareData($giftMessage);
176:         $giftMessage['type'] = 'quote_item';
177: 
178:         $giftMessages = array($quoteItem->getId() => $giftMessage);
179: 
180:         $request = new Mage_Core_Controller_Request_Http();
181:         $request->setParam("giftmessage", $giftMessages);
182: 
183:         return $this->_setGiftMessage($quoteItemId, $request, $quote);
184:     }
185: }
186: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0