Mage_ProductAlert_Model_Email Class Reference

Inheritance diagram for Mage_ProductAlert_Model_Email:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 setType ($type)
 getType ()
 setWebsite (Mage_Core_Model_Website $website)
 setWebsiteId ($websiteId)
 setCustomerId ($customerId)
 setCustomer (Mage_Customer_Model_Customer $customer)
 clean ()
 addPriceProduct (Mage_Catalog_Model_Product $product)
 addStockProduct (Mage_Catalog_Model_Product $product)
 send ()

Public Attributes

const XML_PATH_EMAIL_PRICE_TEMPLATE = 'catalog/productalert/email_price_template'
const XML_PATH_EMAIL_STOCK_TEMPLATE = 'catalog/productalert/email_stock_template'
const XML_PATH_EMAIL_IDENTITY = 'catalog/productalert/email_identity'

Protected Member Functions

 _getPriceBlock ()
 _getStockBlock ()

Protected Attributes

 $_type = 'price'
 $_website
 $_customer
 $_priceProducts = array()
 $_stockProducts = array()
 $_priceBlock
 $_stockBlock


Detailed Description

Definition at line 35 of file Email.php.


Member Function Documentation

_getPriceBlock (  )  [protected]

Retrieve price block

Returns:
Mage_ProductAlert_Block_Email_Price

Definition at line 201 of file Email.php.

00202     {
00203         if (is_null($this->_priceBlock)) {
00204             $this->_priceBlock = Mage::helper('productalert')
00205                 ->createBlock('productalert/email_price');
00206         }
00207         return $this->_priceBlock;
00208     }

_getStockBlock (  )  [protected]

Retrieve stock block

Returns:
Mage_ProductAlert_Block_Email_Stock

Definition at line 215 of file Email.php.

00216     {
00217         if (is_null($this->_stockBlock)) {
00218             $this->_stockBlock = Mage::helper('productalert')
00219                 ->createBlock('productalert/email_stock');
00220         }
00221         return $this->_stockBlock;
00222     }

addPriceProduct ( Mage_Catalog_Model_Product product  ) 

Add product (price change) to collection

Parameters:
Mage_Catalog_Model_Product $product
Returns:
Mage_ProductAlert_Model_Email

Definition at line 178 of file Email.php.

00179     {
00180         $this->_priceProducts[$product->getId()] = $product;
00181         return $this;
00182     }

addStockProduct ( Mage_Catalog_Model_Product product  ) 

Add product (back in stock) to collection

Parameters:
Mage_Catalog_Model_Product $product
Returns:
Mage_ProductAlert_Model_Email

Definition at line 190 of file Email.php.

00191     {
00192         $this->_stockProducts[$product->getId()] = $product;
00193         return $this;
00194     }

clean (  ) 

Clean data

Returns:
Mage_ProductAlert_Model_Email

Definition at line 163 of file Email.php.

00164     {
00165         $this->_customer      = null;
00166         $this->_priceProducts = array();
00167         $this->_stockProducts = array();
00168 
00169         return $this;
00170     }

getType (  ) 

Retrieve model type

Returns:
string

Definition at line 105 of file Email.php.

00106     {
00107         return $this->_type;
00108     }

send (  ) 

Send customer email

Returns:
bool

Definition at line 229 of file Email.php.

00230     {
00231         if (is_null($this->_website) || is_null($this->_customer)) {
00232             return false;
00233         }
00234         if (($this->_type == 'price' && count($this->_priceProducts) == 0) || ($this->_type == 'stock' && count($this->_stockProducts) == 0)) {
00235             return false;
00236         }
00237         if (!$this->_website->getDefaultGroup() || !$this->_website->getDefaultGroup()->getDefaultStore()) {
00238             return false;
00239         }
00240 
00241         $store      = $this->_website->getDefaultStore();
00242         $storeId    = $store->getId();
00243 
00244         if ($this->_type == 'price' && !Mage::getStoreConfig(self::XML_PATH_EMAIL_PRICE_TEMPLATE, $storeId)) {
00245             return false;
00246         } elseif ($this->_type == 'stock' && !Mage::getStoreConfig(self::XML_PATH_EMAIL_STOCK_TEMPLATE, $storeId)) {
00247             return false;
00248         }
00249 
00250         Mage::getDesign()->setStore($storeId);
00251         Mage::getDesign()->setArea('frontend');
00252 
00253         $translate = Mage::getSingleton('core/translate');
00254         /* @var $translate Mage_Core_Model_Translate */
00255         $translate->setTranslateInline(false);
00256 
00257         if ($this->_type == 'price') {
00258             $this->_getPriceBlock()->setStore($store);
00259             foreach ($this->_priceProducts as $product) {
00260                 $product->setCustomerGroupId($this->_customer->getGroupId());
00261                 $this->_getPriceBlock()->addProduct($product);
00262             }
00263             $block = $this->_getPriceBlock()->toHtml();
00264             $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_PRICE_TEMPLATE, $storeId);
00265         }
00266         elseif ($this->_type == 'stock') {
00267             $this->_getStockBlock()->setStore($store);
00268             foreach ($this->_stockProducts as $product) {
00269                 $product->setCustomerGroupId($this->_customer->getGroupId());
00270                 $this->_getStockBlock()->addProduct($product);
00271             }
00272             $block = $this->_getStockBlock()->toHtml();
00273             $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_STOCK_TEMPLATE, $storeId);
00274         }
00275         else {
00276             return false;
00277         }
00278 
00279         Mage::getModel('core/email_template')
00280             ->setDesignConfig(array(
00281                 'area'  => 'frontend',
00282                 'store' => $storeId
00283             ))->sendTransactional(
00284                 $templateId,
00285                 Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId),
00286                 $this->_customer->getEmail(),
00287                 $this->_customer->getName(),
00288                 array(
00289                     'customerName'  => $this->_customer->getName(),
00290                     'alertGrid'     => $block
00291                 )
00292             );
00293 
00294         $translate->setTranslateInline(true);
00295 
00296         return true;
00297     }

setCustomer ( Mage_Customer_Model_Customer customer  ) 

Set customer model

Parameters:
Mage_Customer_Model_Customer $customer
Returns:
Mage_ProductAlert_Model_Email

Definition at line 152 of file Email.php.

00153     {
00154         $this->_customer = $customer;
00155         return $this;
00156     }

setCustomerId ( customerId  ) 

Set customer by id

Parameters:
int $customerId
Returns:
Mage_ProductAlert_Model_Email

Definition at line 140 of file Email.php.

00141     {
00142         $this->_customer = Mage::getModel('customer/customer')->load($customerId);
00143         return $this;
00144     }

setType ( type  ) 

Set model type

Parameters:
string $type

Definition at line 95 of file Email.php.

00096     {
00097         $this->_type = $type;
00098     }

setWebsite ( Mage_Core_Model_Website website  ) 

Set website model

Parameters:
Mage_Core_Model_Website $website
Returns:
Mage_ProductAlert_Model_Email

Definition at line 116 of file Email.php.

00117     {
00118         $this->_website = $website;
00119         return $this;
00120     }

setWebsiteId ( websiteId  ) 

Set website id

Parameters:
int $websiteId
Returns:
Mage_ProductAlert_Model_Email

Definition at line 128 of file Email.php.

00129     {
00130         $this->_website = Mage::app()->getWebsite($websiteId);
00131         return $this;
00132     }


Member Data Documentation

$_customer [protected]

Definition at line 60 of file Email.php.

$_priceBlock [protected]

Definition at line 81 of file Email.php.

$_priceProducts = array() [protected]

Definition at line 67 of file Email.php.

$_stockBlock [protected]

Definition at line 88 of file Email.php.

$_stockProducts = array() [protected]

Definition at line 74 of file Email.php.

$_type = 'price' [protected]

Definition at line 46 of file Email.php.

$_website [protected]

Definition at line 53 of file Email.php.

const XML_PATH_EMAIL_IDENTITY = 'catalog/productalert/email_identity'

Definition at line 39 of file Email.php.

const XML_PATH_EMAIL_PRICE_TEMPLATE = 'catalog/productalert/email_price_template'

Definition at line 37 of file Email.php.

const XML_PATH_EMAIL_STOCK_TEMPLATE = 'catalog/productalert/email_stock_template'

Definition at line 38 of file Email.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:35 2009 for Magento by  doxygen 1.5.8