Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mage_ProductAlert - DOC block update #757

Merged
merged 1 commit into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/code/core/Mage/ProductAlert/Block/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function __construct()
$this->setTemplate('productalert/price.phtml');
}

/**
* @return bool
*/
public function isShow()
{
if (!Mage::getStoreConfig('catalog/productalert/allow_price')) {
Expand All @@ -45,6 +48,11 @@ public function isShow()
return true;
}

/**
* @param string $route
* @param array $params
* @return string
*/
public function getUrl($route = '', $params = array())
{
return Mage::helper('productalert')->getSaveUrl('price');
Expand Down
13 changes: 5 additions & 8 deletions app/code/core/Mage/ProductAlert/Block/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,26 @@

/**
* Product view price and stock alerts
* @method $this setSignupUrl(string $value)
*/
class Mage_ProductAlert_Block_Product_View extends Mage_Core_Block_Template
{
/**
* Current product instance
*
* @var null|Mage_Catalog_Model_Product
* @var Mage_Catalog_Model_Product
*/
protected $_product = null;

/**
* Helper instance
*
* @var null|Mage_ProductAlert_Helper_Data
* @var Mage_ProductAlert_Helper_Data
*/
protected $_helper = null;

/**
* Check whether the stock alert data can be shown and prepare related data
*
* @return void
*/
public function prepareStockAlertData()
{
Expand All @@ -59,8 +58,6 @@ public function prepareStockAlertData()

/**
* Check whether the price alert data can be shown and prepare related data
*
* @return void
*/
public function preparePriceAlertData()
{
Expand All @@ -76,7 +73,7 @@ public function preparePriceAlertData()
/**
* Get current product instance
*
* @return $this
* @inheritDoc
*/
protected function _prepareLayout()
{
Expand All @@ -91,7 +88,7 @@ protected function _prepareLayout()
/**
* Retrieve helper instance
*
* @return Mage_ProductAlert_Helper_Data|null
* @return Mage_ProductAlert_Helper_Data
*/
protected function _getHelper()
{
Expand Down
10 changes: 9 additions & 1 deletion app/code/core/Mage/ProductAlert/Block/Stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public function __construct()
$this->setTemplate('productalert/stock.phtml');
}

/**
* @return bool
*/
public function isShow()
{
if (!Mage::getStoreConfig('catalog/productalert/allow_stock')) {
Expand All @@ -46,11 +49,16 @@ public function isShow()
if (!$product = Mage::helper('productalert')->getProduct()) {
return false;
}
/* @var $product Mage_Catalog_Model_Product */
/* @var Mage_Catalog_Model_Product $product */

return !$product->isSaleable();
}

/**
* @param string $route
* @param array $params
* @return string
*/
public function getUrl($route = '', $params = array())
{
return Mage::helper('productalert')->getSaveUrl('stock');
Expand Down
18 changes: 17 additions & 1 deletion app/code/core/Mage/ProductAlert/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,27 @@ public function setProduct($product)
return $this;
}

/**
* @return Mage_Customer_Model_Session
*/
public function getCustomer()
{
return Mage::getSingleton('customer/session');
}

/**
* @return Mage_Core_Model_Store
* @throws Mage_Core_Model_Store_Exception
*/
public function getStore()
{
return Mage::app()->getStore();
}

/**
* @param string $type
* @return string
*/
public function getSaveUrl($type)
{
return $this->_getUrl('productalert/add/' . $type, array(
Expand All @@ -84,6 +95,11 @@ public function getSaveUrl($type)
));
}

/**
* @param string $block
* @return string
* @throws Mage_Core_Exception
*/
public function createBlock($block)
{
$error = Mage::helper('core')->__('Invalid block type: %s', $block);
Expand All @@ -95,7 +111,7 @@ public function createBlock($block)
}
$fileName = mageFindClassFile($block);
if ($fileName!==false) {
include_once ($fileName);
include_once($fileName);
$block = new $block(array());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* @package Mage_ProductAlert
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_ProductAlert_Model_Mysql4_Price_Customer_Collection
extends Mage_ProductAlert_Model_Resource_Price_Customer_Collection
class Mage_ProductAlert_Model_Mysql4_Price_Customer_Collection extends Mage_ProductAlert_Model_Resource_Price_Customer_Collection
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* @package Mage_ProductAlert
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_ProductAlert_Model_Mysql4_Stock_Customer_Collection
extends Mage_ProductAlert_Model_Resource_Stock_Customer_Collection
class Mage_ProductAlert_Model_Mysql4_Stock_Customer_Collection extends Mage_ProductAlert_Model_Resource_Stock_Customer_Collection
{
}
34 changes: 13 additions & 21 deletions app/code/core/Mage/ProductAlert/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ class Mage_ProductAlert_Model_Observer
/**
* Retrieve website collection array
*
* @return array
* @return Mage_Core_Model_Website[]
*/
protected function _getWebsites()
{
if (is_null($this->_websites)) {
try {
$this->_websites = Mage::app()->getWebsites();
}
catch (Exception $e) {
} catch (Exception $e) {
$this->_errors[] = $e->getMessage();
}
}
Expand Down Expand Up @@ -120,15 +119,15 @@ protected function _processPrice(Mage_ProductAlert_Model_Email $email)
->getCollection()
->addWebsiteFilter($website->getId())
->setCustomerOrder();
}
catch (Exception $e) {
} catch (Exception $e) {
$this->_errors[] = $e->getMessage();
return $this;
}

$previousCustomer = null;
$email->setWebsite($website);
Mage::app()->setCurrentStore($website->getDefaultGroup()->getDefaultStore());
/** @var Mage_ProductAlert_Model_Price $alert */
foreach ($collection as $alert) {
try {
if (!$previousCustomer || $previousCustomer->getId() != $alert->getCustomerId()) {
Expand All @@ -142,8 +141,7 @@ protected function _processPrice(Mage_ProductAlert_Model_Email $email)
$previousCustomer = $customer;
$email->clean();
$email->setCustomer($customer);
}
else {
} else {
$customer = $previousCustomer;
}

Expand All @@ -166,16 +164,14 @@ protected function _processPrice(Mage_ProductAlert_Model_Email $email)
$alert->setStatus(1);
$alert->save();
}
}
catch (Exception $e) {
} catch (Exception $e) {
$this->_errors[] = $e->getMessage();
}
}
if ($previousCustomer) {
try {
$email->send();
}
catch (Exception $e) {
} catch (Exception $e) {
$this->_errors[] = $e->getMessage();
}
}
Expand Down Expand Up @@ -213,15 +209,15 @@ protected function _processStock(Mage_ProductAlert_Model_Email $email)
->addWebsiteFilter($website->getId())
->addStatusFilter(0)
->setCustomerOrder();
}
catch (Exception $e) {
} catch (Exception $e) {
$this->_errors[] = $e->getMessage();
return $this;
}

$previousCustomer = null;
$email->setWebsite($website);
Mage::app()->setCurrentStore($website->getDefaultGroup()->getDefaultStore());
/** @var Mage_ProductAlert_Model_Stock $alert */
foreach ($collection as $alert) {
try {
if (!$previousCustomer || $previousCustomer->getId() != $alert->getCustomerId()) {
Expand All @@ -235,15 +231,14 @@ protected function _processStock(Mage_ProductAlert_Model_Email $email)
$previousCustomer = $customer;
$email->clean();
$email->setCustomer($customer);
}
else {
} else {
$customer = $previousCustomer;
}

$product = Mage::getModel('catalog/product')
->setStoreId($website->getDefaultStore()->getId())
->load($alert->getProductId());
/* @var $product Mage_Catalog_Model_Product */

if (!$product) {
continue;
}
Expand All @@ -258,17 +253,15 @@ protected function _processStock(Mage_ProductAlert_Model_Email $email)
$alert->setStatus(1);
$alert->save();
}
}
catch (Exception $e) {
} catch (Exception $e) {
$this->_errors[] = $e->getMessage();
}
}

if ($previousCustomer) {
try {
$email->send();
}
catch (Exception $e) {
} catch (Exception $e) {
$this->_errors[] = $e->getMessage();
}
}
Expand Down Expand Up @@ -319,7 +312,6 @@ protected function _sendErrorEmail()
public function process()
{
$email = Mage::getModel('productalert/email');
/* @var $email Mage_ProductAlert_Model_Email */
$this->_processPrice($email);
$this->_processStock($email);
$this->_sendErrorEmail();
Expand Down
30 changes: 21 additions & 9 deletions app/code/core/Mage/ProductAlert/Model/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,29 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/


/**
* ProductAlert for changed price model
*
* @method Mage_ProductAlert_Model_Resource_Price _getResource()
* @method Mage_ProductAlert_Model_Resource_Price getResource()
* @method Mage_ProductAlert_Model_Resource_Price_Collection getCollection()
*
* @method int getCustomerId()
* @method Mage_ProductAlert_Model_Price setCustomerId(int $value)
* @method $this setCustomerId(int $value)
* @method int getProductId()
* @method Mage_ProductAlert_Model_Price setProductId(int $value)
* @method $this setProductId(int $value)
* @method float getPrice()
* @method Mage_ProductAlert_Model_Price setPrice(float $value)
* @method $this setPrice(float $value)
* @method int getWebsiteId()
* @method Mage_ProductAlert_Model_Price setWebsiteId(int $value)
* @method $this setWebsiteId(int $value)
* @method string getAddDate()
* @method Mage_ProductAlert_Model_Price setAddDate(string $value)
* @method $this setAddDate(string $value)
* @method string getLastSendDate()
* @method Mage_ProductAlert_Model_Price setLastSendDate(string $value)
* @method $this setLastSendDate(string $value)
* @method int getSendCount()
* @method Mage_ProductAlert_Model_Price setSendCount(int $value)
* @method $this setSendCount(int $value)
* @method int getStatus()
* @method Mage_ProductAlert_Model_Price setStatus(int $value)
* @method $this setStatus(int $value)
*
* @category Mage
* @package Mage_ProductAlert
Expand All @@ -58,11 +59,17 @@ protected function _construct()
$this->_init('productalert/price');
}

/**
* @return Mage_ProductAlert_Model_Resource_Price_Customer_Collection
*/
public function getCustomerCollection()
{
return Mage::getResourceModel('productalert/price_customer_collection');
}

/**
* @return $this
*/
public function loadByParam()
{
if (!is_null($this->getProductId()) && !is_null($this->getCustomerId()) && !is_null($this->getWebsiteId())) {
Expand All @@ -71,6 +78,11 @@ public function loadByParam()
return $this;
}

/**
* @param int $customerId
* @param int $websiteId
* @return $this
*/
public function deleteCustomer($customerId, $websiteId = 0)
{
$this->getResource()->deleteCustomer($this, $customerId, $websiteId);
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/ProductAlert/Model/Resource/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract class Mage_ProductAlert_Model_Resource_Abstract extends Mage_Core_Model
* Retrieve alert row by object parameters
*
* @param Mage_Core_Model_Abstract $object
* @return array|bool
* @return array|false
*/
protected function _getAlertRow(Mage_Core_Model_Abstract $object)
{
Expand Down Expand Up @@ -82,7 +82,7 @@ public function loadByParam(Mage_Core_Model_Abstract $object)
* @param int $websiteId
* @return Mage_ProductAlert_Model_Resource_Abstract
*/
public function deleteCustomer(Mage_Core_Model_Abstract $object, $customerId, $websiteId=null)
public function deleteCustomer(Mage_Core_Model_Abstract $object, $customerId, $websiteId = null)
{
$adapter = $this->_getWriteAdapter();
$where = array();
Expand Down
Loading