Public Member Functions | |
process () | |
Public Attributes | |
const | XML_PATH_ERROR_TEMPLATE = 'catalog/productalert_cron/error_email_template' |
const | XML_PATH_ERROR_IDENTITY = 'catalog/productalert_cron/error_email_identity' |
const | XML_PATH_ERROR_RECIPIENT = 'catalog/productalert_cron/error_email' |
const | XML_PATH_PRICE_ALLOW = 'catalog/productalert/allow_price' |
const | XML_PATH_STOCK_ALLOW = 'catalog/productalert/allow_stock' |
Protected Member Functions | |
_getWebsites () | |
_processPrice (Mage_ProductAlert_Model_Email $email) | |
_processStock (Mage_ProductAlert_Model_Email $email) | |
_sendErrorEmail () | |
Protected Attributes | |
$_websites | |
$_errors = array() |
Definition at line 35 of file Observer.php.
_getWebsites | ( | ) | [protected] |
Retrieve website collection array
Definition at line 83 of file Observer.php.
00084 { 00085 if (is_null($this->_websites)) { 00086 try { 00087 $this->_websites = Mage::app()->getWebsites(); 00088 } 00089 catch (Exception $e) { 00090 $this->_errors[] = $e->getMessage(); 00091 } 00092 } 00093 return $this->_websites; 00094 }
_processPrice | ( | Mage_ProductAlert_Model_Email $ | ) | [protected] |
Process price emails
Mage_ProductAlert_Model_Email |
Definition at line 102 of file Observer.php.
00103 { 00104 $email->setType('price'); 00105 foreach ($this->_getWebsites() as $website) { 00106 /* @var $website Mage_Core_Model_Website */ 00107 00108 if (!$website->getDefaultGroup() || !$website->getDefaultGroup()->getDefaultStore()) { 00109 continue; 00110 } 00111 if (!Mage::getStoreConfig(self::XML_PATH_PRICE_ALLOW, $website->getDefaultGroup()->getDefaultStore()->getId())) { 00112 continue; 00113 } 00114 try { 00115 $collection = Mage::getModel('productalert/price') 00116 ->getCollection() 00117 ->addWebsiteFilter($website->getId()) 00118 ->setCustomerOrder(); 00119 } 00120 catch (Exception $e) { 00121 $this->_errors[] = $e->getMessage(); 00122 return $this; 00123 } 00124 00125 $previousCustomer = null; 00126 $email->setWebsite($website); 00127 foreach ($collection as $alert) { 00128 try { 00129 if (!$previousCustomer || $previousCustomer->getId() != $alert->getCustomerId()) { 00130 $customer = Mage::getModel('customer/customer')->load($alert->getCustomerId()); 00131 if ($previousCustomer) { 00132 $email->send(); 00133 } 00134 if (!$customer) { 00135 continue; 00136 } 00137 $previousCustomer = $customer; 00138 $email->clean(); 00139 $email->setCustomer($customer); 00140 } 00141 else { 00142 $customer = $previousCustomer; 00143 } 00144 00145 $product = Mage::getModel('catalog/product') 00146 ->setStoreId($website->getDefaultStore()->getId()) 00147 ->load($alert->getProductId()); 00148 if (!$product) { 00149 continue; 00150 } 00151 $product->setCustomerGroupId($customer->getGroupId()); 00152 if ($alert->getPrice() > $product->getFinalPrice()) { 00153 $email->addPriceProduct($product); 00154 00155 $alert->setPrice($product->getFinalPrice()); 00156 $alert->setLastSendDate(Mage::getModel('core/date')->gmtDate()); 00157 $alert->setSendCount($alert->getSendCount() + 1); 00158 $alert->setStatus(1); 00159 $alert->save(); 00160 } 00161 } 00162 catch (Exception $e) { 00163 $this->_errors[] = $e->getMessage(); 00164 } 00165 } 00166 if ($previousCustomer) { 00167 try { 00168 $email->send(); 00169 } 00170 catch (Exception $e) { 00171 $this->_errors[] = $e->getMessage(); 00172 } 00173 } 00174 } 00175 return $this; 00176 }
_processStock | ( | Mage_ProductAlert_Model_Email $ | ) | [protected] |
Process stock emails
Mage_ProductAlert_Model_Email |
Definition at line 184 of file Observer.php.
00185 { 00186 $email->setType('stock'); 00187 00188 foreach ($this->_getWebsites() as $website) { 00189 /* @var $website Mage_Core_Model_Website */ 00190 00191 if (!$website->getDefaultGroup() || !$website->getDefaultGroup()->getDefaultStore()) { 00192 continue; 00193 } 00194 if (!Mage::getStoreConfig(self::XML_PATH_STOCK_ALLOW, $website->getDefaultGroup()->getDefaultStore()->getId())) { 00195 continue; 00196 } 00197 try { 00198 $collection = Mage::getModel('productalert/stock') 00199 ->getCollection() 00200 ->addWebsiteFilter($website->getId()) 00201 ->addStatusFilter(0) 00202 ->setCustomerOrder(); 00203 } 00204 catch (Exception $e) { 00205 $this->_errors[] = $e->getMessage(); 00206 return $this; 00207 } 00208 00209 $previousCustomer = null; 00210 $email->setWebsite($website); 00211 foreach ($collection as $alert) { 00212 try { 00213 if (!$previousCustomer || $previousCustomer->getId() != $alert->getCustomerId()) { 00214 $customer = Mage::getModel('customer/customer')->load($alert->getCustomerId()); 00215 if ($previousCustomer) { 00216 $email->send(); 00217 } 00218 if (!$customer) { 00219 continue; 00220 } 00221 $previousCustomer = $customer; 00222 $email->clean(); 00223 $email->setCustomer($customer); 00224 } 00225 else { 00226 $customer = $previousCustomer; 00227 } 00228 00229 $product = Mage::getModel('catalog/product') 00230 ->setStoreId($website->getDefaultStore()->getId()) 00231 ->load($alert->getProductId()); 00232 /* @var $product Mage_catalog_Model_Product */ 00233 if (!$product) { 00234 continue; 00235 } 00236 00237 $product->setCustomerGroupId($customer->getGroupId()); 00238 00239 if ($product->isSalable()) { 00240 $email->addStockProduct($product); 00241 00242 $alert->setSendDate(Mage::getModel('core/date')->gmtDate()); 00243 $alert->setSendCount($alert->getSendCount() + 1); 00244 $alert->setStatus(1); 00245 $alert->save(); 00246 } 00247 } 00248 catch (Exception $e) { 00249 $this->_errors[] = $e->getMessage(); 00250 } 00251 } 00252 00253 if ($previousCustomer) { 00254 try { 00255 $email->send(); 00256 } 00257 catch (Exception $e) { 00258 $this->_errors[] = $e->getMessage(); 00259 } 00260 } 00261 } 00262 00263 return $this; 00264 }
_sendErrorEmail | ( | ) | [protected] |
Send email to administrator if error
Definition at line 271 of file Observer.php.
00272 { 00273 if (count($this->_errors)) { 00274 if (!Mage::getStoreConfig(self::XML_PATH_ERROR_TEMPLATE)) { 00275 return $this; 00276 } 00277 00278 $translate = Mage::getSingleton('core/translate'); 00279 /* @var $translate Mage_Core_Model_Translate */ 00280 $translate->setTranslateInline(false); 00281 00282 $emailTemplate = Mage::getModel('core/email_template'); 00283 /* @var $emailTemplate Mage_Core_Model_Email_Template */ 00284 $emailTemplate->setDesignConfig(array('area' => 'backend')) 00285 ->sendTransactional( 00286 Mage::getStoreConfig(self::XML_PATH_ERROR_TEMPLATE), 00287 Mage::getStoreConfig(self::XML_PATH_ERROR_IDENTITY), 00288 Mage::getStoreConfig(self::XML_PATH_ERROR_RECIPIENT), 00289 null, 00290 array('warnings' => join("\n", $this->_errors)) 00291 ); 00292 00293 $translate->setTranslateInline(true); 00294 $this->_errors[] = array(); 00295 } 00296 return $this; 00297 }
process | ( | ) |
Run process send product alerts
Definition at line 304 of file Observer.php.
00305 { 00306 $email = Mage::getModel('productalert/email'); 00307 /* @var $email Mage_ProductAlert_Model_Email */ 00308 $this->_processPrice($email); 00309 $this->_processStock($email); 00310 $this->_sendErrorEmail(); 00311 00312 return $this; 00313 }
$_errors = array() [protected] |
Definition at line 76 of file Observer.php.
$_websites [protected] |
Definition at line 69 of file Observer.php.
const XML_PATH_ERROR_IDENTITY = 'catalog/productalert_cron/error_email_identity' |
Error email identity configuration
Definition at line 45 of file Observer.php.
const XML_PATH_ERROR_RECIPIENT = 'catalog/productalert_cron/error_email' |
'Send error emails to' configuration
Definition at line 50 of file Observer.php.
const XML_PATH_ERROR_TEMPLATE = 'catalog/productalert_cron/error_email_template' |
Error email template configuration
Definition at line 40 of file Observer.php.
const XML_PATH_PRICE_ALLOW = 'catalog/productalert/allow_price' |
Allow price alert
Definition at line 56 of file Observer.php.
const XML_PATH_STOCK_ALLOW = 'catalog/productalert/allow_stock' |
Allow stock alert
Definition at line 62 of file Observer.php.