Version Notes
Version number: 1.0.0
Download this release
Release Info
Developer | Sergey Repin |
Extension | Web4pro_Stockstatus |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Web4pro/Stockstatus/Block/Catalog/Product/View/Type/Bundle/Option.php +63 -0
- app/code/community/Web4pro/Stockstatus/Block/Catalog/Product/View/Type/Bundle/Option/Checkbox.php +29 -0
- app/code/community/Web4pro/Stockstatus/Block/Catalog/Product/View/Type/Bundle/Option/Multi.php +29 -0
- app/code/community/Web4pro/Stockstatus/Block/Catalog/Product/View/Type/Bundle/Option/Radio.php +29 -0
- app/code/community/Web4pro/Stockstatus/Block/Catalog/Product/View/Type/Bundle/Option/Select.php +29 -0
- app/code/community/Web4pro/Stockstatus/Block/Catalog/Product/View/Type/Configurable.php +44 -0
- app/code/community/Web4pro/Stockstatus/Block/Stockstatus.php +66 -0
- app/code/community/Web4pro/Stockstatus/Helper/Data.php +137 -0
- app/code/community/Web4pro/Stockstatus/Model/Observer.php +105 -0
- app/code/community/Web4pro/Stockstatus/etc/adminhtml.xml +33 -0
- app/code/community/Web4pro/Stockstatus/etc/config.xml +164 -0
- app/code/community/Web4pro/Stockstatus/etc/system.xml +84 -0
- app/code/community/Web4pro/Stockstatus/sql/web4pro_stockstatus_setup/install-1.0.0.php +65 -0
- app/design/frontend/base/default/layout/web4pro_stockstatus.xml +28 -0
- app/etc/modules/Web4pro_Stockstatus.xml +20 -0
- app/locale/en_US/Web4pro_Stockstatus.csv +19 -0
- js/web4pro/stockstatus/stockstatus.js +79 -0
- package.xml +18 -0
app/code/community/Web4pro/Stockstatus/Block/Catalog/Product/View/Type/Bundle/Option.php
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WEB4PRO - Creating profitable online stores
|
4 |
+
*
|
5 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
6 |
+
* @category WEB4PRO
|
7 |
+
* @package Web4pro_Stockstatus
|
8 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
9 |
+
* @license http://www.web4pro.net/license.txt
|
10 |
+
*/
|
11 |
+
/**
|
12 |
+
* Attachments default helper
|
13 |
+
*
|
14 |
+
* @category Web4pro
|
15 |
+
* @package Web4pro_Stockstatus
|
16 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
17 |
+
*/
|
18 |
+
|
19 |
+
class Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Bundle_Option extends Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option
|
20 |
+
{
|
21 |
+
/**
|
22 |
+
* Returns the formatted string for the quantity chosen for the given selection
|
23 |
+
*
|
24 |
+
* @param Mage_Catalog_Model_Proudct $_selection
|
25 |
+
* @param bool $includeContainer
|
26 |
+
* @return string
|
27 |
+
*/
|
28 |
+
public function getSelectionQtyTitlePrice($_selection, $includeContainer = true)
|
29 |
+
{
|
30 |
+
$price = $this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection);
|
31 |
+
$_selectionProduct = Mage::getModel('catalog/product')->load($_selection->getId());
|
32 |
+
$stockStatus = Mage::helper('web4pro_stockstatus')->getNewStockStatus($_selectionProduct);
|
33 |
+
if($stockStatus)
|
34 |
+
{
|
35 |
+
$stockStatus = '(' . $stockStatus . ') ';
|
36 |
+
}
|
37 |
+
|
38 |
+
return $_selection->getSelectionQty()*1 . ' x ' . $_selection->getName() . ' ' . $stockStatus .
|
39 |
+
($includeContainer ? '<span class="price-notice">':'') . '+' .
|
40 |
+
$this->formatPriceString($price, $includeContainer) . ($includeContainer ? '</span>':'');
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Get title price for selection product
|
46 |
+
*
|
47 |
+
* @param Mage_Catalog_Model_Product $_selection
|
48 |
+
* @param bool $includeContainer
|
49 |
+
* @return string
|
50 |
+
*/
|
51 |
+
public function getSelectionTitlePrice($_selection, $includeContainer = true)
|
52 |
+
{
|
53 |
+
$price = $this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection, 1);
|
54 |
+
$_selectionProduct = Mage::getModel('catalog/product')->load($_selection->getId());
|
55 |
+
$stockStatus = Mage::helper('web4pro_stockstatus')->getNewStockStatus($_selectionProduct);
|
56 |
+
if($stockStatus)
|
57 |
+
{
|
58 |
+
$stockStatus = '(' . $stockStatus . ') ';
|
59 |
+
}
|
60 |
+
return $_selection->getName() . ' ' . $stockStatus . ($includeContainer ? '<span class="price-notice">':'') . '+' .
|
61 |
+
$this->formatPriceString($price, $includeContainer) . ($includeContainer ? '</span>':'');
|
62 |
+
}
|
63 |
+
}
|
app/code/community/Web4pro/Stockstatus/Block/Catalog/Product/View/Type/Bundle/Option/Checkbox.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WEB4PRO - Creating profitable online stores
|
4 |
+
*
|
5 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
6 |
+
* @category WEB4PRO
|
7 |
+
* @package Web4pro_Stockstatus
|
8 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
9 |
+
* @license http://www.web4pro.net/license.txt
|
10 |
+
*/
|
11 |
+
/**
|
12 |
+
* Attachments default helper
|
13 |
+
*
|
14 |
+
* @category Web4pro
|
15 |
+
* @package Web4pro_Stockstatus
|
16 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
17 |
+
*/
|
18 |
+
class Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Bundle_Option_Checkbox extends Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Bundle_Option
|
19 |
+
{
|
20 |
+
/**
|
21 |
+
* Set template
|
22 |
+
*
|
23 |
+
* @return void
|
24 |
+
*/
|
25 |
+
public function _construct()
|
26 |
+
{
|
27 |
+
$this->setTemplate('bundle/catalog/product/view/type/bundle/option/checkbox.phtml');
|
28 |
+
}
|
29 |
+
}
|
app/code/community/Web4pro/Stockstatus/Block/Catalog/Product/View/Type/Bundle/Option/Multi.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WEB4PRO - Creating profitable online stores
|
4 |
+
*
|
5 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
6 |
+
* @category WEB4PRO
|
7 |
+
* @package Web4pro_Stockstatus
|
8 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
9 |
+
* @license http://www.web4pro.net/license.txt
|
10 |
+
*/
|
11 |
+
/**
|
12 |
+
* Attachments default helper
|
13 |
+
*
|
14 |
+
* @category Web4pro
|
15 |
+
* @package Web4pro_Stockstatus
|
16 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
17 |
+
*/
|
18 |
+
class Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Bundle_Option_Multi extends Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Bundle_Option
|
19 |
+
{
|
20 |
+
/**
|
21 |
+
* Set template
|
22 |
+
*
|
23 |
+
* @return void
|
24 |
+
*/
|
25 |
+
public function _construct()
|
26 |
+
{
|
27 |
+
$this->setTemplate('bundle/catalog/product/view/type/bundle/option/multi.phtml');
|
28 |
+
}
|
29 |
+
}
|
app/code/community/Web4pro/Stockstatus/Block/Catalog/Product/View/Type/Bundle/Option/Radio.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WEB4PRO - Creating profitable online stores
|
4 |
+
*
|
5 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
6 |
+
* @category WEB4PRO
|
7 |
+
* @package Web4pro_Stockstatus
|
8 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
9 |
+
* @license http://www.web4pro.net/license.txt
|
10 |
+
*/
|
11 |
+
/**
|
12 |
+
* Attachments default helper
|
13 |
+
*
|
14 |
+
* @category Web4pro
|
15 |
+
* @package Web4pro_Stockstatus
|
16 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
17 |
+
*/
|
18 |
+
class Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Bundle_Option_Radio extends Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Bundle_Option
|
19 |
+
{
|
20 |
+
/**
|
21 |
+
* Set template
|
22 |
+
*
|
23 |
+
* @return void
|
24 |
+
*/
|
25 |
+
public function _construct()
|
26 |
+
{
|
27 |
+
$this->setTemplate('bundle/catalog/product/view/type/bundle/option/radio.phtml');
|
28 |
+
}
|
29 |
+
}
|
app/code/community/Web4pro/Stockstatus/Block/Catalog/Product/View/Type/Bundle/Option/Select.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WEB4PRO - Creating profitable online stores
|
4 |
+
*
|
5 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
6 |
+
* @category WEB4PRO
|
7 |
+
* @package Web4pro_Stockstatus
|
8 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
9 |
+
* @license http://www.web4pro.net/license.txt
|
10 |
+
*/
|
11 |
+
/**
|
12 |
+
* Attachments default helper
|
13 |
+
*
|
14 |
+
* @category Web4pro
|
15 |
+
* @package Web4pro_Stockstatus
|
16 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
17 |
+
*/
|
18 |
+
class Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Bundle_Option_Select extends Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Bundle_Option
|
19 |
+
{
|
20 |
+
/**
|
21 |
+
* Set template
|
22 |
+
*
|
23 |
+
* @return void
|
24 |
+
*/
|
25 |
+
public function _construct()
|
26 |
+
{
|
27 |
+
$this->setTemplate('bundle/catalog/product/view/type/bundle/option/select.phtml');
|
28 |
+
}
|
29 |
+
}
|
app/code/community/Web4pro/Stockstatus/Block/Catalog/Product/View/Type/Configurable.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WEB4PRO - Creating profitable online stores
|
4 |
+
*
|
5 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
6 |
+
* @category WEB4PRO
|
7 |
+
* @package Web4pro_Stockstatus
|
8 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
9 |
+
* @license http://www.web4pro.net/license.txt
|
10 |
+
*/
|
11 |
+
/**
|
12 |
+
* Attachments default helper
|
13 |
+
*
|
14 |
+
* @category Web4pro
|
15 |
+
* @package Web4pro_Stockstatus
|
16 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
17 |
+
*/
|
18 |
+
|
19 |
+
class Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Configurable extends Mage_Catalog_Block_Product_View_Type_Configurable
|
20 |
+
{
|
21 |
+
/**
|
22 |
+
* Composes configuration for js
|
23 |
+
*
|
24 |
+
* @return string
|
25 |
+
*/
|
26 |
+
public function getJsonConfig()
|
27 |
+
{
|
28 |
+
$config = parent::getJsonConfig();
|
29 |
+
$config = Mage::helper('core')->jsonDecode($config);
|
30 |
+
$stockstatuses = array();
|
31 |
+
$helper = Mage::helper('web4pro_stockstatus');
|
32 |
+
$_product = $this->getProduct();
|
33 |
+
$ids = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($_product->getId());
|
34 |
+
$_subproducts = Mage::getModel('catalog/product')->getCollection()
|
35 |
+
->addAttributeToFilter('entity_id', $ids)
|
36 |
+
->addAttributeToSelect('*');
|
37 |
+
foreach ($_subproducts as $product){
|
38 |
+
$stockstatuses[$product->getId()]["stockstatus"] = $helper->getNewStockStatus($product);
|
39 |
+
$config['stockstatuses'] = $stockstatuses;
|
40 |
+
$config['availability'] = $helper->__('Availability:');
|
41 |
+
}
|
42 |
+
return Mage::helper('core')->jsonEncode($config);
|
43 |
+
}
|
44 |
+
}
|
app/code/community/Web4pro/Stockstatus/Block/Stockstatus.php
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WEB4PRO - Creating profitable online stores
|
4 |
+
*
|
5 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
6 |
+
* @category WEB4PRO
|
7 |
+
* @package Web4pro_Stockstatus
|
8 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
9 |
+
* @license http://www.web4pro.net/license.txt
|
10 |
+
*/
|
11 |
+
/**
|
12 |
+
* Attachments default helper
|
13 |
+
*
|
14 |
+
* @category Web4pro
|
15 |
+
* @package Web4pro_Stockstatus
|
16 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
17 |
+
*/
|
18 |
+
|
19 |
+
class Web4pro_Stockstatus_Block_Stockstatus extends Mage_Core_Block_Text
|
20 |
+
{
|
21 |
+
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Replace stock statuses at product list and cart pages
|
25 |
+
* @param $transport
|
26 |
+
* @param $stockstatuses
|
27 |
+
*/
|
28 |
+
public function replaceStockStatuses($transport, $stockstatuses)
|
29 |
+
{
|
30 |
+
$script = '
|
31 |
+
<script type="text/javascript">
|
32 |
+
//<![CDATA[
|
33 |
+
document.observe("dom:loaded", function() {
|
34 |
+
if($$("h2.product-name").first()){
|
35 |
+
var stockstatuses = '. Mage::helper('core')->jsonEncode($stockstatuses) . ';' .
|
36 |
+
'stockstatuses.each(function(name, index){
|
37 |
+
$$("h2.product-name")[index].insert({after:name})
|
38 |
+
})
|
39 |
+
}
|
40 |
+
});
|
41 |
+
//]]>
|
42 |
+
</script>
|
43 |
+
';
|
44 |
+
$text = $transport . $script;
|
45 |
+
$this->setData('text', $text);
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Replace sotck status at product view page
|
50 |
+
* @param $transport
|
51 |
+
* @param $stockstatus
|
52 |
+
*/
|
53 |
+
public function replaceStockStatus($transport, $stockstatus)
|
54 |
+
{
|
55 |
+
$script = '<script type="text/javascript">
|
56 |
+
//<![CDATA[
|
57 |
+
document.observe("dom:loaded", function() {
|
58 |
+
$$("p.availability").first().update("'. $stockstatus .'")
|
59 |
+
});
|
60 |
+
//]]>
|
61 |
+
</script>
|
62 |
+
';
|
63 |
+
$text = $transport . $script;
|
64 |
+
$this->setData('text', $text);
|
65 |
+
}
|
66 |
+
}
|
app/code/community/Web4pro/Stockstatus/Helper/Data.php
ADDED
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WEB4PRO - Creating profitable online stores
|
4 |
+
*
|
5 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
6 |
+
* @category WEB4PRO
|
7 |
+
* @package Web4pro_Stockstatus
|
8 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
9 |
+
* @license http://www.web4pro.net/license.txt
|
10 |
+
*/
|
11 |
+
/**
|
12 |
+
* Attachments default helper
|
13 |
+
*
|
14 |
+
* @category Web4pro
|
15 |
+
* @package Web4pro_Stockstatus
|
16 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
17 |
+
*/
|
18 |
+
class Web4pro_Stockstatus_Helper_Data extends Mage_Core_Helper_Abstract
|
19 |
+
{
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Get default stock status of product
|
23 |
+
* @param $product
|
24 |
+
* @return string
|
25 |
+
*/
|
26 |
+
public function getDefaultStockStatus($product)
|
27 |
+
{
|
28 |
+
if($product->isAvailable()){
|
29 |
+
$result = $this->__('In stock');
|
30 |
+
}
|
31 |
+
else{
|
32 |
+
$result = $this->__('Out of stock');
|
33 |
+
}
|
34 |
+
return $result;
|
35 |
+
}
|
36 |
+
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Get custom stock status of product
|
40 |
+
* @param $product
|
41 |
+
* @return string
|
42 |
+
*/
|
43 |
+
public function getCustomStockStatus($product)
|
44 |
+
{
|
45 |
+
$customStockStatus = '';
|
46 |
+
if ($product->isAvailable() || $this->isCustomStockStatusOnOutOfStock()){
|
47 |
+
$customStockStatus = $product->getAttributeText('custom_stockstatus');
|
48 |
+
}
|
49 |
+
return $customStockStatus;
|
50 |
+
}
|
51 |
+
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Get new stock status based on default and custom
|
55 |
+
* @param object $product
|
56 |
+
* @return string
|
57 |
+
*/
|
58 |
+
public function getNewStockStatus($product)
|
59 |
+
{
|
60 |
+
$newStockStatus = $this->getDefaultStockStatus($product);
|
61 |
+
$customStockStatus = $this->getCustomStockStatus($product);
|
62 |
+
if ($this->isShowStockLevel() && $product->getStockItem()->getQty()) {
|
63 |
+
$newStockStatus = $this->__('%s in stock', (int)$product->getStockItem()->getQty());
|
64 |
+
return $newStockStatus;
|
65 |
+
}
|
66 |
+
if (empty($customStockStatus)){
|
67 |
+
return $newStockStatus;
|
68 |
+
}
|
69 |
+
if ($this->isDefaultStockStatusHidden($product)){
|
70 |
+
$newStockStatus = $customStockStatus;
|
71 |
+
} else {
|
72 |
+
$newStockStatus = $newStockStatus . ' ' . $customStockStatus;
|
73 |
+
}
|
74 |
+
return $newStockStatus;
|
75 |
+
}
|
76 |
+
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Check whether to hide a ddefault status
|
80 |
+
* @param object $product
|
81 |
+
* @return mixed
|
82 |
+
*/
|
83 |
+
public function isDefaultStockStatusHidden($product)
|
84 |
+
{
|
85 |
+
return $product->getData('hide_default_stockstatus');
|
86 |
+
}
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Is the custom status allowed at page of category
|
90 |
+
* @return mixed
|
91 |
+
*/
|
92 |
+
public function isCustomStockStatusOnProductListPage()
|
93 |
+
{
|
94 |
+
return Mage::getStoreConfig('web4pro_stockstatus/general/display_at_categoty');
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Is the custom status allowed at page of shoping cart
|
99 |
+
* @return mixed
|
100 |
+
*/
|
101 |
+
public function isCustomStockStatusInShoppingCart()
|
102 |
+
{
|
103 |
+
return Mage::getStoreConfig('web4pro_stockstatus/general/display_in_cart');
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Is the custom status allowed for Out of stock products
|
108 |
+
* @return mixed
|
109 |
+
*/
|
110 |
+
public function isCustomStockStatusOnOutOfStock()
|
111 |
+
{
|
112 |
+
return Mage::getStoreConfig('web4pro_stockstatus/general/outofstock');
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* is stock qty displayed
|
117 |
+
* @return mixed
|
118 |
+
*/
|
119 |
+
public function isShowStockLevel()
|
120 |
+
{
|
121 |
+
return Mage::getStoreConfig('web4pro_stockstatus/general/showstocklevel');
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Is the custom status allowed at page of product view
|
126 |
+
* @param $product
|
127 |
+
* @return string
|
128 |
+
*/
|
129 |
+
public function showStockStatus($product)
|
130 |
+
{
|
131 |
+
$result = '';
|
132 |
+
if ($this->isCustomStockStatusOnProductListPage()){
|
133 |
+
$result = $this->getNewStockStatus($product);
|
134 |
+
}
|
135 |
+
return $result;
|
136 |
+
}
|
137 |
+
}
|
app/code/community/Web4pro/Stockstatus/Model/Observer.php
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WEB4PRO - Creating profitable online stores
|
4 |
+
*
|
5 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
6 |
+
* @category WEB4PRO
|
7 |
+
* @package Web4pro_Stockstatus
|
8 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
9 |
+
* @license http://www.web4pro.net/license.txt
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Web4pro_Stockstatus_Model_Observer
|
13 |
+
{
|
14 |
+
/**
|
15 |
+
* web4pro stockstatus helper
|
16 |
+
*
|
17 |
+
*/
|
18 |
+
private $_helper = '';
|
19 |
+
|
20 |
+
/**
|
21 |
+
* constructor
|
22 |
+
*
|
23 |
+
* @access public
|
24 |
+
* @return void
|
25 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
26 |
+
*/
|
27 |
+
public function __construct()
|
28 |
+
{
|
29 |
+
$this->_helper = Mage::helper('web4pro_stockstatus');
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Update product sotck statuses
|
34 |
+
* @access public
|
35 |
+
* @param Varien_Event_Observer $observer
|
36 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
37 |
+
*/
|
38 |
+
public function updateStockStatus($observer)
|
39 |
+
{
|
40 |
+
$block = $observer->getBlock();
|
41 |
+
$stockstatuses = $this->_getStockStatuses($block);
|
42 |
+
$isStockStatus = count($stockstatuses);
|
43 |
+
if (empty($isStockStatus)){
|
44 |
+
return;
|
45 |
+
}
|
46 |
+
$transport = $observer->getEvent()->getTransport();
|
47 |
+
$block = new Web4pro_Stockstatus_Block_Stockstatus();
|
48 |
+
if ($stockstatuses['isProductView'] == 1){
|
49 |
+
$stockstatus = $stockstatuses['stockstatus'];
|
50 |
+
$block->replaceStockStatus($transport['html'], $stockstatus);
|
51 |
+
} else {
|
52 |
+
$block->replaceStockStatuses($transport['html'], $stockstatuses);
|
53 |
+
}
|
54 |
+
$block->toHtml();
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Getting statuses depending on block
|
59 |
+
* @param object $block
|
60 |
+
* @access private
|
61 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
62 |
+
*/
|
63 |
+
private function _getStockStatuses($block)
|
64 |
+
{
|
65 |
+
$stockstatuses = array();
|
66 |
+
switch(true) {
|
67 |
+
case $block instanceof Mage_Catalog_Block_Product_View:
|
68 |
+
$product = $block->getProduct();
|
69 |
+
$stockstatuses['stockstatus'] = $this->_helper->__('Availability: ') . $this->_helper->getNewStockStatus($product);
|
70 |
+
$stockstatuses['isProductView'] = 1;
|
71 |
+
break;
|
72 |
+
|
73 |
+
case $block instanceof Mage_Catalog_Block_Product_List:
|
74 |
+
if ($this->_helper->isCustomStockStatusOnProductListPage()){
|
75 |
+
foreach ($block->getLoadedProductCollection() as $item){
|
76 |
+
$stockstatuses[] = $this->_helper->getNewStockStatus($item);
|
77 |
+
}
|
78 |
+
}
|
79 |
+
break;
|
80 |
+
|
81 |
+
case $block instanceof Mage_Checkout_Block_Cart:
|
82 |
+
if ($this->_helper->isCustomStockStatusInShoppingCart()){
|
83 |
+
foreach ($block->getItems() as $item){
|
84 |
+
$stockstatuses[] = $this->_helper->getNewStockStatus($item->getProduct());
|
85 |
+
}
|
86 |
+
}
|
87 |
+
break;
|
88 |
+
}
|
89 |
+
return $stockstatuses;
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Set stock status attribute
|
94 |
+
* @param Varien_Event_Observer $observer
|
95 |
+
* @access public
|
96 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
97 |
+
*/
|
98 |
+
public function setStockStatusAttribute($observer)
|
99 |
+
{
|
100 |
+
$quoteItem = $observer->getQuoteItem();
|
101 |
+
$product = $observer->getProduct();
|
102 |
+
$quoteItem->setCustomStockstatus($product->getCustomStockstatus());
|
103 |
+
$quoteItem->setHideDefaultStockstatus($product->getHideDefaultStockstatus());
|
104 |
+
}
|
105 |
+
}
|
app/code/community/Web4pro/Stockstatus/etc/adminhtml.xml
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* WEB4PRO - Creating profitable online stores
|
5 |
+
*
|
6 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
7 |
+
* @category WEB4PRO
|
8 |
+
* @package Web4pro_Stockstatus
|
9 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
10 |
+
* @license http://www.web4pro.net/license.txt
|
11 |
+
*/
|
12 |
+
-->
|
13 |
+
<config>
|
14 |
+
<acl>
|
15 |
+
<resources>
|
16 |
+
<admin>
|
17 |
+
<children>
|
18 |
+
<system>
|
19 |
+
<children>
|
20 |
+
<config>
|
21 |
+
<children>
|
22 |
+
<web4pro_stockstatus translate="title" module="web4pro_stockstatus">
|
23 |
+
<title>Custom Stock Status</title>
|
24 |
+
</web4pro_stockstatus>
|
25 |
+
</children>
|
26 |
+
</config>
|
27 |
+
</children>
|
28 |
+
</system>
|
29 |
+
</children>
|
30 |
+
</admin>
|
31 |
+
</resources>
|
32 |
+
</acl>
|
33 |
+
</config>
|
app/code/community/Web4pro/Stockstatus/etc/config.xml
ADDED
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* WEB4PRO - Creating profitable online stores
|
5 |
+
*
|
6 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
7 |
+
* @category WEB4PRO
|
8 |
+
* @package Web4pro_Stockstatus
|
9 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
10 |
+
* @license http://www.web4pro.net/license.txt
|
11 |
+
*/
|
12 |
+
-->
|
13 |
+
<config>
|
14 |
+
<modules>
|
15 |
+
<Web4pro_Stockstatus>
|
16 |
+
<version>1.0.0</version>
|
17 |
+
</Web4pro_Stockstatus>
|
18 |
+
</modules>
|
19 |
+
<global>
|
20 |
+
<helpers>
|
21 |
+
<web4pro_stockstatus>
|
22 |
+
<class>Web4pro_Stockstatus_Helper</class>
|
23 |
+
</web4pro_stockstatus>
|
24 |
+
</helpers>
|
25 |
+
<models>
|
26 |
+
<web4pro_stockstatus>
|
27 |
+
<class>Web4pro_Stockstatus_Model</class>
|
28 |
+
</web4pro_stockstatus>
|
29 |
+
</models>
|
30 |
+
<blocks>
|
31 |
+
<web4pro_stockstatus>
|
32 |
+
<class>Web4pro_Stockstatus_Block</class>
|
33 |
+
</web4pro_stockstatus>
|
34 |
+
<catalog>
|
35 |
+
<rewrite>
|
36 |
+
<product_view_type_configurable>Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Configurable</product_view_type_configurable>
|
37 |
+
</rewrite>
|
38 |
+
</catalog>
|
39 |
+
<bundle>
|
40 |
+
<rewrite>
|
41 |
+
<catalog_product_view_type_bundle_option_radio>Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Bundle_Option_Radio</catalog_product_view_type_bundle_option_radio>
|
42 |
+
<catalog_product_view_type_bundle_option_multi>Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Bundle_Option_Multi</catalog_product_view_type_bundle_option_multi>
|
43 |
+
<catalog_product_view_type_bundle_option_checkbox>Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Bundle_Option_Checkbox</catalog_product_view_type_bundle_option_checkbox>
|
44 |
+
<catalog_product_view_type_bundle_option_select>Web4pro_Stockstatus_Block_Catalog_Product_View_Type_Bundle_Option_Select</catalog_product_view_type_bundle_option_select>
|
45 |
+
</rewrite>
|
46 |
+
</bundle>
|
47 |
+
</blocks>
|
48 |
+
<resources>
|
49 |
+
<web4pro_stockstatus_setup>
|
50 |
+
<setup>
|
51 |
+
<module>Web4pro_Stockstatus</module>
|
52 |
+
</setup>
|
53 |
+
<connection>
|
54 |
+
<use>core_setup</use>
|
55 |
+
</connection>
|
56 |
+
</web4pro_stockstatus_setup>
|
57 |
+
<web4pro_stockstatus_write>
|
58 |
+
<connection>
|
59 |
+
<use>core_write</use>
|
60 |
+
</connection>
|
61 |
+
</web4pro_stockstatus_write>
|
62 |
+
<web4pro_stockstatus_read>
|
63 |
+
<connection>
|
64 |
+
<use>core_read</use>
|
65 |
+
</connection>
|
66 |
+
</web4pro_stockstatus_read>
|
67 |
+
</resources>
|
68 |
+
<sales>
|
69 |
+
<quote>
|
70 |
+
<item>
|
71 |
+
<product_attributes>
|
72 |
+
<custom_stockstatus />
|
73 |
+
<hide_default_stockstatus />
|
74 |
+
</product_attributes>
|
75 |
+
</item>
|
76 |
+
</quote>
|
77 |
+
</sales>
|
78 |
+
<events>
|
79 |
+
<sales_quote_item_set_product>
|
80 |
+
<observers>
|
81 |
+
<add_custom_stockstatus_to_quote>
|
82 |
+
<class>web4pro_stockstatus/observer</class>
|
83 |
+
<method>setStockStatusAttribute</method>
|
84 |
+
</add_custom_stockstatus_to_quote>
|
85 |
+
</observers>
|
86 |
+
</sales_quote_item_set_product>
|
87 |
+
</events>
|
88 |
+
</global>
|
89 |
+
<frontend>
|
90 |
+
<routers>
|
91 |
+
<web4pro_stockstatus>
|
92 |
+
<use>standard</use>
|
93 |
+
<args>
|
94 |
+
<module>Web4pro_Stockstatus</module>
|
95 |
+
<frontName>web4pro_stockstatus</frontName>
|
96 |
+
</args>
|
97 |
+
</web4pro_stockstatus>
|
98 |
+
</routers>
|
99 |
+
<layout>
|
100 |
+
<updates>
|
101 |
+
<web4pro_stockstatus>
|
102 |
+
<file>web4pro_stockstatus.xml</file>
|
103 |
+
</web4pro_stockstatus>
|
104 |
+
</updates>
|
105 |
+
</layout>
|
106 |
+
<translate>
|
107 |
+
<modules>
|
108 |
+
<Web4pro_Stockstatus>
|
109 |
+
<files>
|
110 |
+
<default>Web4pro_Stockstatus.csv</default>
|
111 |
+
</files>
|
112 |
+
</Web4pro_Stockstatus>
|
113 |
+
</modules>
|
114 |
+
</translate>
|
115 |
+
<events>
|
116 |
+
<core_block_abstract_to_html_after>
|
117 |
+
<observers>
|
118 |
+
<update_stock_status>
|
119 |
+
<class>web4pro_stockstatus/observer</class>
|
120 |
+
<method>updateStockStatus</method>
|
121 |
+
</update_stock_status>
|
122 |
+
</observers>
|
123 |
+
</core_block_abstract_to_html_after>
|
124 |
+
</events>
|
125 |
+
</frontend>
|
126 |
+
<adminhtml>
|
127 |
+
<layout>
|
128 |
+
<updates>
|
129 |
+
<web4pro_stockstatus>
|
130 |
+
<file>web4pro_stockstatus.xml</file>
|
131 |
+
</web4pro_stockstatus>
|
132 |
+
</updates>
|
133 |
+
</layout>
|
134 |
+
<translate>
|
135 |
+
<modules>
|
136 |
+
<Web4pro_Stockstatus>
|
137 |
+
<files>
|
138 |
+
<default>Web4pro_Stockstatus.csv</default>
|
139 |
+
</files>
|
140 |
+
</Web4pro_Stockstatus>
|
141 |
+
</modules>
|
142 |
+
</translate>
|
143 |
+
<acl>
|
144 |
+
<resources>
|
145 |
+
<admin>
|
146 |
+
<children>
|
147 |
+
<system>
|
148 |
+
<children>
|
149 |
+
<config>
|
150 |
+
<children>
|
151 |
+
<web4pro_stockstatus translate="title" module="web4pro_stockstatus">
|
152 |
+
<title>Custom Stock Status Section</title>
|
153 |
+
<sort_order>50</sort_order>
|
154 |
+
</web4pro_stockstatus>
|
155 |
+
</children>
|
156 |
+
</config>
|
157 |
+
</children>
|
158 |
+
</system>
|
159 |
+
</children>
|
160 |
+
</admin>
|
161 |
+
</resources>
|
162 |
+
</acl>
|
163 |
+
</adminhtml>
|
164 |
+
</config>
|
app/code/community/Web4pro/Stockstatus/etc/system.xml
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* WEB4PRO - Creating profitable online stores
|
5 |
+
*
|
6 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
7 |
+
* @category WEB4PRO
|
8 |
+
* @package Web4pro_Stockstatus
|
9 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
10 |
+
* @license http://www.web4pro.net/license.txt
|
11 |
+
*/
|
12 |
+
-->
|
13 |
+
<config>
|
14 |
+
<tabs>
|
15 |
+
<web4pro translate="label" module="web4pro_stockstatus">
|
16 |
+
<label>Web4pro</label>
|
17 |
+
<sort_order>2000</sort_order>
|
18 |
+
</web4pro>
|
19 |
+
</tabs>
|
20 |
+
<sections>
|
21 |
+
<web4pro_stockstatus translate="label" module="web4pro_stockstatus">
|
22 |
+
<class>separator-top</class>
|
23 |
+
<label>Custom Stock Status</label>
|
24 |
+
<tab>web4pro</tab>
|
25 |
+
<frontend_type>text</frontend_type>
|
26 |
+
<sort_order>100</sort_order>
|
27 |
+
<show_in_default>1</show_in_default>
|
28 |
+
<show_in_website>1</show_in_website>
|
29 |
+
<show_in_store>1</show_in_store>
|
30 |
+
<groups>
|
31 |
+
<general>
|
32 |
+
<label>General Options</label>
|
33 |
+
<expanded>1</expanded>
|
34 |
+
<frontend_type>text</frontend_type>
|
35 |
+
<sort_order>2</sort_order>
|
36 |
+
<show_in_default>1</show_in_default>
|
37 |
+
<show_in_website>1</show_in_website>
|
38 |
+
<show_in_store>1</show_in_store>
|
39 |
+
<fields>
|
40 |
+
<outofstock translate="label">
|
41 |
+
<label>Show Stock Status When Out Of Stock?</label>
|
42 |
+
<frontend_type>select</frontend_type>
|
43 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
44 |
+
<sort_order>1</sort_order>
|
45 |
+
<show_in_default>1</show_in_default>
|
46 |
+
<show_in_website>1</show_in_website>
|
47 |
+
<show_in_store>1</show_in_store>
|
48 |
+
<comment>Do you want to show custom stock status instead of 'Out of stock' when product is not in stock?</comment>
|
49 |
+
</outofstock>
|
50 |
+
<display_at_categoty translate="label">
|
51 |
+
<label>Display Custom Stock Status On Product List Page</label>
|
52 |
+
<frontend_type>select</frontend_type>
|
53 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
54 |
+
<sort_order>15</sort_order>
|
55 |
+
<show_in_default>1</show_in_default>
|
56 |
+
<show_in_website>1</show_in_website>
|
57 |
+
<show_in_store>1</show_in_store>
|
58 |
+
</display_at_categoty>
|
59 |
+
<display_in_cart translate="label">
|
60 |
+
<label>Display Custom Stock Status in Shopping Cart</label>
|
61 |
+
<comment>Will display custom stock status for items in shopping cart.</comment>
|
62 |
+
<frontend_type>select</frontend_type>
|
63 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
64 |
+
<sort_order>20</sort_order>
|
65 |
+
<show_in_default>1</show_in_default>
|
66 |
+
<show_in_website>1</show_in_website>
|
67 |
+
<show_in_store>1</show_in_store>
|
68 |
+
</display_in_cart>
|
69 |
+
<showstocklevel translate="label">
|
70 |
+
<label>Show Stock Level?</label>
|
71 |
+
<frontend_type>select</frontend_type>
|
72 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
73 |
+
<sort_order>1</sort_order>
|
74 |
+
<show_in_default>1</show_in_default>
|
75 |
+
<show_in_website>1</show_in_website>
|
76 |
+
<show_in_store>1</show_in_store>
|
77 |
+
<comment>Show the actual quantity in stock?</comment>
|
78 |
+
</showstocklevel>
|
79 |
+
</fields>
|
80 |
+
</general>
|
81 |
+
</groups>
|
82 |
+
</web4pro_stockstatus>
|
83 |
+
</sections>
|
84 |
+
</config>
|
app/code/community/Web4pro/Stockstatus/sql/web4pro_stockstatus_setup/install-1.0.0.php
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WEB4PRO - Creating profitable online stores
|
4 |
+
*
|
5 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
6 |
+
* @category WEB4PRO
|
7 |
+
* @package Web4pro_Stockstatus
|
8 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
9 |
+
* @license http://www.web4pro.net/license.txt
|
10 |
+
*/
|
11 |
+
/**
|
12 |
+
* Stockstatus module install script
|
13 |
+
*
|
14 |
+
* @category Web4pro
|
15 |
+
* @package Web4pro_Stockstatus
|
16 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
17 |
+
*/
|
18 |
+
$this->startSetup();
|
19 |
+
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
20 |
+
|
21 |
+
$setup->addAttribute('catalog_product', 'custom_stockstatus', array(
|
22 |
+
'group' => 'Custom Stock Status',
|
23 |
+
'input' => 'select',
|
24 |
+
'type' => 'text',
|
25 |
+
'label' => 'Custom Stock Status Message',
|
26 |
+
'backend' => '',
|
27 |
+
'frontend' => '',
|
28 |
+
'visible' => true,
|
29 |
+
'required' => false,
|
30 |
+
'user_defined' => true,
|
31 |
+
'searchable' => false,
|
32 |
+
'filterable' => false,
|
33 |
+
'comparable' => false,
|
34 |
+
'visible_on_front' => false,
|
35 |
+
'used_in_product_listing' => true,
|
36 |
+
'visible_in_advanced_search' => false,
|
37 |
+
'is_html_allowed_on_front' => false,
|
38 |
+
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
|
39 |
+
'note' => 'Add messages by going to <b>Catalog->Attributes->Manage Attributes</b> and clicking on the <b>\'custom_stockstatus\'</b> attribute.'
|
40 |
+
));
|
41 |
+
|
42 |
+
$setup->addAttribute('catalog_product', 'hide_default_stockstatus', array(
|
43 |
+
'group' => 'Custom Stock Status',
|
44 |
+
'type' => 'int',
|
45 |
+
'backend' => '',
|
46 |
+
'frontend' => '',
|
47 |
+
'label' => 'Hide Default Stock Status',
|
48 |
+
'input' => 'select',
|
49 |
+
'source' => 'eav/entity_attribute_source_boolean',
|
50 |
+
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
|
51 |
+
'visible' => true,
|
52 |
+
'required' => false,
|
53 |
+
'user_defined' => true,
|
54 |
+
'default' => '',
|
55 |
+
'searchable' => false,
|
56 |
+
'filterable' => false,
|
57 |
+
'comparable' => false,
|
58 |
+
'visible_on_front' => false,
|
59 |
+
'unique' => false,
|
60 |
+
'is_configurable' => false,
|
61 |
+
'used_in_product_listing' => true
|
62 |
+
));
|
63 |
+
|
64 |
+
|
65 |
+
$this->endSetup();
|
app/design/frontend/base/default/layout/web4pro_stockstatus.xml
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* WEB4PRO - Creating profitable online stores
|
5 |
+
*
|
6 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
7 |
+
* @category WEB4PRO
|
8 |
+
* @package Web4pro_Stockstatus
|
9 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
10 |
+
* @license http://www.web4pro.net/license.txt
|
11 |
+
*/
|
12 |
+
-->
|
13 |
+
<layout>
|
14 |
+
<PRODUCT_TYPE_configurable translate="label" module="catalog">
|
15 |
+
<reference name="head">
|
16 |
+
<action method="addJs">
|
17 |
+
<script>web4pro/stockstatus/stockstatus.js</script>
|
18 |
+
</action>
|
19 |
+
</reference>
|
20 |
+
</PRODUCT_TYPE_configurable>
|
21 |
+
<PRODUCT_TYPE_grouped translate="label" module="catalog">
|
22 |
+
<reference name="product.info.grouped">
|
23 |
+
<action method="setTemplate">
|
24 |
+
<template>web4pro_stockstatus/catalog/product/view/type/grouped.phtml</template>
|
25 |
+
</action>
|
26 |
+
</reference>
|
27 |
+
</PRODUCT_TYPE_grouped>
|
28 |
+
</layout>
|
app/etc/modules/Web4pro_Stockstatus.xml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* WEB4PRO - Creating profitable online stores
|
5 |
+
*
|
6 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
7 |
+
* @category WEB4PRO
|
8 |
+
* @package Web4pro_Stockstatus
|
9 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
10 |
+
* @license http://www.web4pro.net/license.txt
|
11 |
+
*/
|
12 |
+
-->
|
13 |
+
<config>
|
14 |
+
<modules>
|
15 |
+
<Web4pro_Stockstatus>
|
16 |
+
<active>true</active>
|
17 |
+
<codePool>community</codePool>
|
18 |
+
</Web4pro_Stockstatus>
|
19 |
+
</modules>
|
20 |
+
</config>
|
app/locale/en_US/Web4pro_Stockstatus.csv
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"",""
|
2 |
+
"Web4pro","Web4pro"
|
3 |
+
"General Options","General Options"
|
4 |
+
"Show Stock Status When Out Of Stock?","Show Stock Status When Out Of Stock?"
|
5 |
+
"Do you want to show custom stock status instead of 'Out of stock' when product is not in stock?","Do you want to show custom stock status instead of 'Out of stock' when product is not in stock?"
|
6 |
+
"Display Custom Stock Status On Product List Page","Display Custom Stock Status On Product List Page"
|
7 |
+
"Display Custom Stock Status in Shopping Cart","Display Custom Stock Status in Shopping Cart"
|
8 |
+
"Will display custom stock status for items in shopping cart.","Will display custom stock status for items in shopping cart."
|
9 |
+
"Show Stock Level?","Show Stock Level?"
|
10 |
+
"Show the actual quantity in stock?","Show the actual quantity in stock?"
|
11 |
+
"Availability:","Availability:"
|
12 |
+
"Availability: ","Availability: "
|
13 |
+
"In stock","In stock"
|
14 |
+
"Out of stock","Out of stock"
|
15 |
+
"%s in stock","%s in stock"
|
16 |
+
"Product Name","Product Name"
|
17 |
+
"Price","Price"
|
18 |
+
"Qty","Qty"
|
19 |
+
"No options of this product are available.","No options of this product are available."
|
js/web4pro/stockstatus/stockstatus.js
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* WEB4PRO - Creating profitable online stores
|
3 |
+
*
|
4 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
5 |
+
* @category WEB4PRO
|
6 |
+
* @package Web4pro_Stockstatus
|
7 |
+
* @copyright Copyright (c) 2015 WEB4PRO (http://www.web4pro.net)
|
8 |
+
* @license http://www.web4pro.net/license.txt
|
9 |
+
*/
|
10 |
+
/**
|
11 |
+
* Attachments default helper
|
12 |
+
*
|
13 |
+
* @category Web4pro
|
14 |
+
* @package Web4pro_Stockstatus
|
15 |
+
* @author WEB4PRO <srepin@corp.web4pro.com.ua>
|
16 |
+
*/
|
17 |
+
|
18 |
+
Product.Config.prototype.getOptionLabel_base = Product.Config.prototype.getOptionLabel;
|
19 |
+
Product.Config.prototype.getOptionLabel = function(option, price) {
|
20 |
+
var str = Product.Config.prototype.getOptionLabel_base.call(this, option, price);
|
21 |
+
if(option.allowedProducts.size() == 1){
|
22 |
+
var status = this.config.stockstatuses[option.allowedProducts].stockstatus;
|
23 |
+
str+= ' (' + status + ')';
|
24 |
+
}
|
25 |
+
return str;
|
26 |
+
};
|
27 |
+
|
28 |
+
Product.Config.prototype.getIdOfSelectedProduct = function() {
|
29 |
+
var status = '';
|
30 |
+
var existingProducts = new Object();
|
31 |
+
|
32 |
+
for (var i = this.settings.length - 1; i >= 0; i--) {
|
33 |
+
var selected = this.settings[i].options[this.settings[i].selectedIndex];
|
34 |
+
if (selected.config) {
|
35 |
+
for (var iproducts = 0; iproducts < selected.config.products.length; iproducts++) {
|
36 |
+
var usedAsKey = selected.config.products[iproducts] + "";
|
37 |
+
if (existingProducts[usedAsKey] == undefined) {
|
38 |
+
existingProducts[usedAsKey] = 1;
|
39 |
+
}
|
40 |
+
else {
|
41 |
+
existingProducts[usedAsKey] = existingProducts[usedAsKey] + 1;
|
42 |
+
}
|
43 |
+
}
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
for (var keyValue in existingProducts) {
|
48 |
+
for (var keyValueInner in existingProducts) {
|
49 |
+
if (Number(existingProducts[keyValueInner]) < Number(existingProducts[keyValue])) {
|
50 |
+
delete existingProducts[keyValueInner];
|
51 |
+
}
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
var sizeOfExistingProducts = 0;
|
56 |
+
var currentSimpleProductId = "";
|
57 |
+
for (var keyValue in existingProducts) {
|
58 |
+
currentSimpleProductId = keyValue;
|
59 |
+
sizeOfExistingProducts = sizeOfExistingProducts + 1
|
60 |
+
}
|
61 |
+
|
62 |
+
if (sizeOfExistingProducts == 1) {
|
63 |
+
return currentSimpleProductId;
|
64 |
+
}
|
65 |
+
|
66 |
+
};
|
67 |
+
|
68 |
+
document.observe("dom:loaded", function() {
|
69 |
+
$$('.product-options .input-box select').last().observe('change', function () {
|
70 |
+
if(typeof spConfig.getIdOfSelectedProduct() != 'undefined') {
|
71 |
+
var productId = spConfig.getIdOfSelectedProduct();
|
72 |
+
var availabilityText = spConfig.config.availability;
|
73 |
+
var status = availabilityText + ' ' + spConfig.config.stockstatuses[productId].stockstatus;
|
74 |
+
$$('p.availability').invoke('update', status);
|
75 |
+
}
|
76 |
+
});
|
77 |
+
});
|
78 |
+
|
79 |
+
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Web4pro_Stockstatus</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://www.web4pro.net/license.txt">GPL</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Replace default stock statuses with text or configure the number of products available in stock. </summary>
|
10 |
+
<description>With this module you are able to set a custom "stock status" in the products edit page for each and every simple product.</description>
|
11 |
+
<notes>Version number: 1.0.0</notes>
|
12 |
+
<authors><author><name>Sergey Repin</name><user>srepin</user><email>srepin@corp.web4pro.com.ua</email></author></authors>
|
13 |
+
<date>2015-04-06</date>
|
14 |
+
<time>10:48:54</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Web4pro"><dir name="Stockstatus"><dir name="Block"><dir name="Catalog"><dir name="Product"><dir name="View"><dir name="Type"><dir name="Bundle"><dir name="Option"><file name="Checkbox.php" hash="c4099a200a945441d73bd05b6e2a380d"/><file name="Multi.php" hash="3833051ccc5e2fa8d0d889370c7e7e88"/><file name="Radio.php" hash="a84228b8ebcc1762c7ae5c10ffb2b7cb"/><file name="Select.php" hash="aa9ead2a4caca487e6a5ac8c057a2964"/></dir><file name="Option.php" hash="6f89953e7e34a048211d99b2fa935471"/></dir><file name="Configurable.php" hash="571a10f0b1daae80b058d0c187687bd9"/></dir></dir></dir></dir><file name="Stockstatus.php" hash="617ab7df4874c3e1c84bb7f7f4d40ab8"/></dir><dir name="Helper"><file name="Data.php" hash="62ecdd40d0987c06ef08d659fd58a3ba"/></dir><dir name="Model"><file name="Observer.php" hash="9637d236d35bc2e6880560077c2afa5b"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4483da36b754d5ffd4bcef726bff7ef1"/><file name="config.xml" hash="d034c1a039e9ba089c268c65681a55ca"/><file name="system.xml" hash="cf601c69310e26834d58d48afadfcb9d"/></dir><dir name="sql"><dir name="web4pro_stockstatus_setup"><file name="install-1.0.0.php" hash="18a87188f782107b5d99a334444cbfbf"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="web4pro_stockstatus.xml" hash="73954398b61e7bb2fd93a998b43b5a77"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Web4pro_Stockstatus.xml" hash="c7a0ae32162bb27eed946ae5e00f6b4d"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Web4pro_Stockstatus.csv" hash="ef575ef3b7764b8e9d4ef163b248e9b5"/></dir></target><target name="mage"><dir name="js"><dir name="web4pro"><dir name="stockstatus"><file name="stockstatus.js" hash="45816dd271c1bf2fdb4ac9159062c645"/></dir></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.3.0</min><max>5.5.0</max></php></required></dependencies>
|
18 |
+
</package>
|