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_ProductAlert_AddController
  • Mage_ProductAlert_Block_Email_Abstract
  • Mage_ProductAlert_Block_Email_Price
  • Mage_ProductAlert_Block_Email_Stock
  • Mage_ProductAlert_Block_Product_View
  • Mage_ProductAlert_Helper_Data
  • Mage_ProductAlert_Model_Email
  • Mage_ProductAlert_Model_Mysql4_Price
  • Mage_ProductAlert_Model_Mysql4_Price_Collection
  • Mage_ProductAlert_Model_Mysql4_Price_Customer_Collection
  • Mage_ProductAlert_Model_Mysql4_Stock
  • Mage_ProductAlert_Model_Mysql4_Stock_Collection
  • Mage_ProductAlert_Model_Mysql4_Stock_Customer_Collection
  • Mage_ProductAlert_Model_Observer
  • Mage_ProductAlert_Model_Price
  • Mage_ProductAlert_Model_Resource_Abstract
  • Mage_ProductAlert_Model_Resource_Price
  • Mage_ProductAlert_Model_Resource_Price_Collection
  • Mage_ProductAlert_Model_Resource_Price_Customer_Collection
  • Mage_ProductAlert_Model_Resource_Stock
  • Mage_ProductAlert_Model_Resource_Stock_Collection
  • Mage_ProductAlert_Model_Resource_Stock_Customer_Collection
  • Mage_ProductAlert_Model_Stock
  • Mage_ProductAlert_UnsubscribeController
  • 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_ProductAlert
 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: /**
 29:  * ProductAlert Email processor
 30:  *
 31:  * @category   Mage
 32:  * @package    Mage_ProductAlert
 33:  * @author     Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_ProductAlert_Model_Email extends Mage_Core_Model_Abstract
 36: {
 37:     const XML_PATH_EMAIL_PRICE_TEMPLATE = 'catalog/productalert/email_price_template';
 38:     const XML_PATH_EMAIL_STOCK_TEMPLATE = 'catalog/productalert/email_stock_template';
 39:     const XML_PATH_EMAIL_IDENTITY       = 'catalog/productalert/email_identity';
 40: 
 41:     /**
 42:      * Type
 43:      *
 44:      * @var string
 45:      */
 46:     protected $_type = 'price';
 47: 
 48:     /**
 49:      * Website Model
 50:      *
 51:      * @var Mage_Core_Model_Website
 52:      */
 53:     protected $_website;
 54: 
 55:     /**
 56:      * Customer model
 57:      *
 58:      * @var Mage_Customer_Model_Customer
 59:      */
 60:     protected $_customer;
 61: 
 62:     /**
 63:      * Products collection where changed price
 64:      *
 65:      * @var array
 66:      */
 67:     protected $_priceProducts = array();
 68: 
 69:     /**
 70:      * Product collection which of back in stock
 71:      *
 72:      * @var array
 73:      */
 74:     protected $_stockProducts = array();
 75: 
 76:     /**
 77:      * Price block
 78:      *
 79:      * @var Mage_ProductAlert_Block_Email_Price
 80:      */
 81:     protected $_priceBlock;
 82: 
 83:     /**
 84:      * Stock block
 85:      *
 86:      * @var Mage_ProductAlert_Block_Email_Stock
 87:      */
 88:     protected $_stockBlock;
 89: 
 90:     /**
 91:      * Set model type
 92:      *
 93:      * @param string $type
 94:      */
 95:     public function setType($type)
 96:     {
 97:         $this->_type = $type;
 98:     }
 99: 
100:     /**
101:      * Retrieve model type
102:      *
103:      * @return string
104:      */
105:     public function getType()
106:     {
107:         return $this->_type;
108:     }
109: 
110:     /**
111:      * Set website model
112:      *
113:      * @param Mage_Core_Model_Website $website
114:      * @return Mage_ProductAlert_Model_Email
115:      */
116:     public function setWebsite(Mage_Core_Model_Website $website)
117:     {
118:         $this->_website = $website;
119:         return $this;
120:     }
121: 
122:     /**
123:      * Set website id
124:      *
125:      * @param int $websiteId
126:      * @return Mage_ProductAlert_Model_Email
127:      */
128:     public function setWebsiteId($websiteId)
129:     {
130:         $this->_website = Mage::app()->getWebsite($websiteId);
131:         return $this;
132:     }
133: 
134:     /**
135:      * Set customer by id
136:      *
137:      * @param int $customerId
138:      * @return Mage_ProductAlert_Model_Email
139:      */
140:     public function setCustomerId($customerId)
141:     {
142:         $this->_customer = Mage::getModel('customer/customer')->load($customerId);
143:         return $this;
144:     }
145: 
146:     /**
147:      * Set customer model
148:      *
149:      * @param Mage_Customer_Model_Customer $customer
150:      * @return Mage_ProductAlert_Model_Email
151:      */
152:     public function setCustomer(Mage_Customer_Model_Customer $customer)
153:     {
154:         $this->_customer = $customer;
155:         return $this;
156:     }
157: 
158:     /**
159:      * Clean data
160:      *
161:      * @return Mage_ProductAlert_Model_Email
162:      */
163:     public function clean()
164:     {
165:         $this->_customer      = null;
166:         $this->_priceProducts = array();
167:         $this->_stockProducts = array();
168: 
169:         return $this;
170:     }
171: 
172:     /**
173:      * Add product (price change) to collection
174:      *
175:      * @param Mage_Catalog_Model_Product $product
176:      * @return Mage_ProductAlert_Model_Email
177:      */
178:     public function addPriceProduct(Mage_Catalog_Model_Product $product)
179:     {
180:         $this->_priceProducts[$product->getId()] = $product;
181:         return $this;
182:     }
183: 
184:     /**
185:      * Add product (back in stock) to collection
186:      *
187:      * @param Mage_Catalog_Model_Product $product
188:      * @return Mage_ProductAlert_Model_Email
189:      */
190:     public function addStockProduct(Mage_Catalog_Model_Product $product)
191:     {
192:         $this->_stockProducts[$product->getId()] = $product;
193:         return $this;
194:     }
195: 
196:     /**
197:      * Retrieve price block
198:      *
199:      * @return Mage_ProductAlert_Block_Email_Price
200:      */
201:     protected function _getPriceBlock()
202:     {
203:         if (is_null($this->_priceBlock)) {
204:             $this->_priceBlock = Mage::helper('productalert')
205:                 ->createBlock('productalert/email_price');
206:         }
207:         return $this->_priceBlock;
208:     }
209: 
210:     /**
211:      * Retrieve stock block
212:      *
213:      * @return Mage_ProductAlert_Block_Email_Stock
214:      */
215:     protected function _getStockBlock()
216:     {
217:         if (is_null($this->_stockBlock)) {
218:             $this->_stockBlock = Mage::helper('productalert')
219:                 ->createBlock('productalert/email_stock');
220:         }
221:         return $this->_stockBlock;
222:     }
223: 
224:     /**
225:      * Send customer email
226:      *
227:      * @return bool
228:      */
229:     public function send()
230:     {
231:         if (is_null($this->_website) || is_null($this->_customer)) {
232:             return false;
233:         }
234:         if (($this->_type == 'price' && count($this->_priceProducts) == 0) || ($this->_type == 'stock' && count($this->_stockProducts) == 0)) {
235:             return false;
236:         }
237:         if (!$this->_website->getDefaultGroup() || !$this->_website->getDefaultGroup()->getDefaultStore()) {
238:             return false;
239:         }
240: 
241:         $store      = $this->_website->getDefaultStore();
242:         $storeId    = $store->getId();
243: 
244:         if ($this->_type == 'price' && !Mage::getStoreConfig(self::XML_PATH_EMAIL_PRICE_TEMPLATE, $storeId)) {
245:             return false;
246:         } elseif ($this->_type == 'stock' && !Mage::getStoreConfig(self::XML_PATH_EMAIL_STOCK_TEMPLATE, $storeId)) {
247:             return false;
248:         }
249: 
250:         if ($this->_type != 'price' && $this->_type != 'stock') {
251:             return false;
252:         }
253: 
254:         $appEmulation = Mage::getSingleton('core/app_emulation');
255:         $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
256: 
257:         if ($this->_type == 'price') {
258:             $this->_getPriceBlock()
259:                 ->setStore($store)
260:                 ->reset();
261:             foreach ($this->_priceProducts as $product) {
262:                 $product->setCustomerGroupId($this->_customer->getGroupId());
263:                 $this->_getPriceBlock()->addProduct($product);
264:             }
265:             $block = $this->_getPriceBlock()->toHtml();
266:             $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_PRICE_TEMPLATE, $storeId);
267:         } else {
268:             $this->_getStockBlock()
269:                 ->setStore($store)
270:                 ->reset();
271:             foreach ($this->_stockProducts as $product) {
272:                 $product->setCustomerGroupId($this->_customer->getGroupId());
273:                 $this->_getStockBlock()->addProduct($product);
274:             }
275:             $block = $this->_getStockBlock()->toHtml();
276:             $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_STOCK_TEMPLATE, $storeId);
277:         }
278: 
279:         $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
280: 
281:         Mage::getModel('core/email_template')
282:             ->setDesignConfig(array(
283:                 'area'  => 'frontend',
284:                 'store' => $storeId
285:             ))->sendTransactional(
286:                 $templateId,
287:                 Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId),
288:                 $this->_customer->getEmail(),
289:                 $this->_customer->getName(),
290:                 array(
291:                     'customerName'  => $this->_customer->getName(),
292:                     'alertGrid'     => $block
293:                 )
294:             );
295: 
296:         return true;
297:     }
298: }
299: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0