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 |
Definition at line 35 of file Email.php.
_getPriceBlock | ( | ) | [protected] |
Retrieve price block
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
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
Mage_Catalog_Model_Product | $product |
Definition at line 178 of file Email.php.
addStockProduct | ( | Mage_Catalog_Model_Product $ | product | ) |
Add product (back in stock) to collection
Mage_Catalog_Model_Product | $product |
Definition at line 190 of file Email.php.
clean | ( | ) |
Clean data
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 | ( | ) |
send | ( | ) |
Send customer email
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
Mage_Customer_Model_Customer | $customer |
Definition at line 152 of file Email.php.
setCustomerId | ( | $ | customerId | ) |
Set customer by id
int | $customerId |
Definition at line 140 of file Email.php.
00141 { 00142 $this->_customer = Mage::getModel('customer/customer')->load($customerId); 00143 return $this; 00144 }
setType | ( | $ | type | ) |
setWebsite | ( | Mage_Core_Model_Website $ | website | ) |
Set website model
Mage_Core_Model_Website | $website |
Definition at line 116 of file Email.php.
setWebsiteId | ( | $ | websiteId | ) |
Set website id
int | $websiteId |
Definition at line 128 of file Email.php.
00129 { 00130 $this->_website = Mage::app()->getWebsite($websiteId); 00131 return $this; 00132 }
const XML_PATH_EMAIL_IDENTITY = 'catalog/productalert/email_identity' |
const XML_PATH_EMAIL_PRICE_TEMPLATE = 'catalog/productalert/email_price_template' |
const XML_PATH_EMAIL_STOCK_TEMPLATE = 'catalog/productalert/email_stock_template' |