Naya_CallForPrice - Version 1.0.0

Version Notes

Initial release.

Download this release

Release Info

Developer Damir Perkosan
Extension Naya_CallForPrice
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Naya/CallForPrice/Block/Checkout/Cart/Crosssell.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Naya_CallForPrice_Block_Checkout_Cart_Crosssell extends Mage_Checkout_Block_Cart_Crosssell
4
+ {
5
+ public function getAddToCartUrl($product, $additional = array())
6
+ {
7
+ if($this->_getEnableCallforPrice($product) == 1){
8
+ //remove add to cart button on crosssell page with js, using this tag:
9
+ return 'remove-add-to-cart';
10
+ }
11
+ return parent::getAddToCartUrl($product, $additional = array());
12
+ }
13
+
14
+ private function _getEnableCallforPrice($product){
15
+ $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
16
+ $code = $eavAttribute->getIdByCode('catalog_product', 'naya_call_for_price_enable');
17
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
18
+ $sql = <<<SQL
19
+ SELECT `value`
20
+ FROM catalog_product_entity_int
21
+ WHERE entity_id = {$product->getId()}
22
+ AND attribute_id = {$code}
23
+ SQL;
24
+ $row = $connection->fetchRow($sql);
25
+ return $row['value'];
26
+ }
27
+ }
app/code/community/Naya/CallForPrice/Model/Observer.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Naya_CallForPrice_Model_Observer {
4
+
5
+ public function catalog_product_is_salable_after($observer) {
6
+ $product = $observer->getEvent()->getProduct();
7
+ $salable = $observer->getEvent()->getSalable();
8
+
9
+ if($this->_getEnableCallforPrice($product) == 1){
10
+ $salable->setIsSalable(0);
11
+ //remove "not available" message with js, using this tag:
12
+ echo '<span class="remove-unavailable-tag"></span>';
13
+ }
14
+ }
15
+
16
+ public function coreBlockAbstractToHtmlBefore($observer) {
17
+ //set custom price template
18
+ $block = $observer->getBlock();
19
+ $product = $block->getProduct();
20
+
21
+ if ($product) {
22
+
23
+ if($this->_getEnableCallforPrice($product) == 1 && (get_class($block) == 'Mage_Catalog_Block_Product_Price' || get_class($block) == 'Mage_Bundle_Block_Catalog_Product_Price')){
24
+ if($block->getTemplate() == 'catalog/product/price.phtml' || $block->getTemplate() == 'bundle/catalog/product/price.phtml'){
25
+ $block->setTemplate('naya/callforprice/price.phtml');
26
+ }else{
27
+ $block->setTemplate('naya/callforprice/nodisplay.phtml');
28
+ }
29
+ }
30
+ }
31
+ }
32
+
33
+ public function customizeCollection($observer){
34
+ $hideProductsFromPricefilter = false;
35
+
36
+ $appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
37
+ foreach ($appliedFilters as $item) {
38
+ if($item->getFilter()->getRequestVar() == 'price'){
39
+ $hideProductsFromPricefilter = true;
40
+ break;
41
+ }
42
+ }
43
+
44
+ if($hideProductsFromPricefilter){
45
+ $observer->getEvent()->getCollection()
46
+ ->addAttributeToFilter(
47
+ array(
48
+ array('attribute'=>'naya_call_for_price_enable', array('eq' => 0)),
49
+ array('attribute'=>'naya_call_for_price_enable', array('null' => 1))
50
+ ), '', 'left');
51
+ }
52
+ }
53
+
54
+
55
+ private function _getEnableCallforPrice($product){
56
+ $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
57
+ $code = $eavAttribute->getIdByCode('catalog_product', 'naya_call_for_price_enable');
58
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
59
+ $sql = <<<SQL
60
+ SELECT `value`
61
+ FROM catalog_product_entity_int
62
+ WHERE entity_id = {$product->getId()}
63
+ AND attribute_id = {$code}
64
+ SQL;
65
+ $row = $connection->fetchRow($sql);
66
+ return $row['value'];
67
+ }
68
+ }
69
+ ?>
app/code/community/Naya/CallForPrice/Model/Resource/Setup.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class Naya_CallForPrice_Model_Resource_Setup
4
+ extends Mage_Core_Model_Resource_Setup {
5
+ }
app/code/community/Naya/CallForPrice/etc/config.xml ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Naya_CallForPrice>
5
+ <version>1.0.0</version>
6
+ </Naya_CallForPrice>
7
+ </modules>
8
+
9
+ <global>
10
+ <resources>
11
+ <naya_callforprice_setup>
12
+ <setup>
13
+ <module>Naya_CallForPrice</module>
14
+ </setup>
15
+ </naya_callforprice_setup>
16
+ </resources>
17
+ <blocks>
18
+ <naya_callforprice>
19
+ <class>Naya_CallForPrice_Block</class>
20
+ </naya_callforprice>
21
+ <checkout>
22
+ <rewrite>
23
+ <cart_crosssell>Naya_CallForPrice_Block_Checkout_Cart_Crosssell</cart_crosssell>
24
+ </rewrite>
25
+ </checkout>
26
+ </blocks>
27
+ </global>
28
+
29
+ <adminhtml>
30
+ <translate>
31
+ <modules>
32
+ <Naya_CallForPrice>
33
+ <files>
34
+ <default>Naya_CallForPrice.csv</default>
35
+ </files>
36
+ </Naya_CallForPrice>
37
+ </modules>
38
+ </translate>
39
+ </adminhtml>
40
+
41
+ <frontend>
42
+ <events>
43
+ <catalog_product_is_salable_after>
44
+ <observers>
45
+ <naya_callforprice>
46
+ <type>singleton</type>
47
+ <class>Naya_CallForPrice_Model_Observer</class>
48
+ <method>catalog_product_is_salable_after</method>
49
+ </naya_callforprice>
50
+ </observers>
51
+ </catalog_product_is_salable_after>
52
+ <core_block_abstract_to_html_before>
53
+ <observers>
54
+ <naya_callforprice_to_html_before>
55
+ <type>singleton</type>
56
+ <class>Naya_CallForPrice_Model_Observer</class>
57
+ <method>coreBlockAbstractToHtmlBefore</method>
58
+ </naya_callforprice_to_html_before>
59
+ </observers>
60
+ </core_block_abstract_to_html_before>
61
+ <catalog_product_collection_load_before>
62
+ <observers>
63
+ <naya_callforprice_list_collection>
64
+ <type>singleton</type>
65
+ <class>Naya_CallForPrice_Model_Observer</class>
66
+ <method>customizeCollection</method>
67
+ </naya_callforprice_list_collection>
68
+ </observers>
69
+ </catalog_product_collection_load_before>
70
+ </events>
71
+ <layout>
72
+ <updates>
73
+ <naya_callforprice>
74
+ <file>naya_callforprice.xml</file>
75
+ </naya_callforprice>
76
+ </updates>
77
+ </layout>
78
+ <translate>
79
+ <modules>
80
+ <Naya_CallForPrice>
81
+ <files>
82
+ <default>Naya_CallForPrice.csv</default>
83
+ </files>
84
+ </Naya_CallForPrice>
85
+ </modules>
86
+ </translate>
87
+ </frontend>
88
+
89
+ </config>
app/code/community/Naya/CallForPrice/sql/naya_callforprice_setup/install-1.0.0.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $this->startSetup();
4
+
5
+ $modelGroup = Mage::getModel('eav/entity_attribute_group');
6
+ $modelGroup->setAttributeGroupName('Call for price')
7
+ ->setAttributeSetId(Mage::getModel('catalog/product')->getDefaultAttributeSetId())
8
+ ->setSortOrder(100);
9
+ $modelGroup->save();
10
+
11
+ $setup = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');
12
+ $setup->addAttribute('catalog_product', 'naya_call_for_price_enable', array(
13
+ 'group' => 'Call for price',
14
+ 'input' => 'boolean',
15
+ 'type' => 'int',
16
+ 'label' => 'Enable "Call for price" for this product',
17
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
18
+ 'required' => 0,
19
+ //'user_defined' => 1,
20
+ ));
21
+
22
+ $setup->addAttribute('catalog_product', 'naya_call_for_price_text', array(
23
+ 'group' => 'Call for price',
24
+ 'input' => 'text',
25
+ 'type' => 'varchar',
26
+ 'label' => 'Replace price message',
27
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
28
+ 'required' => 0,
29
+ //'user_defined' => 1,
30
+ ));
31
+
32
+
33
+ $this->endSetup();
app/design/frontend/base/default/layout/naya_callforprice.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <layout>
4
+ <default>
5
+ <reference name="head">
6
+ <action method="addItem">
7
+ <type>skin_js</type>
8
+ <name>js/naya/callforprice/callforprice.js</name>
9
+ </action>
10
+ </reference>
11
+ </default>
12
+ </layout>
app/design/frontend/base/default/template/naya/callforprice/nodisplay.phtml ADDED
File without changes
app/design/frontend/base/default/template/naya/callforprice/price.phtml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $_product = $this->getProduct();
3
+ $callText = Mage::getResourceModel('catalog/product')->getAttributeRawValue($_product->getId(), 'naya_call_for_price_text', Mage::app()->getStore());
4
+ if($callText == ''){
5
+ $callText = $this->__('Call for price');
6
+ }
7
+ echo '<div class="price-box"><span class="regular-price"><span class="price">'.$callText.'</span></span></div>';
8
+ ?>
9
+
app/etc/modules/Naya_CallForPrice.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Naya_CallForPrice>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Core />
9
+ </depends>
10
+ </Naya_CallForPrice>
11
+ </modules>
12
+ </config>
app/locale/en_US/Naya_CallForPrice.csv ADDED
File without changes
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Naya_CallForPrice</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>"Naya - Call For Price" extension hides price and &#x201C;add to cart&#x201D; buttons from selected products, displays a custom message per product and removes product from &#x201C;price filter&#x201D;.</summary>
10
+ <description>This extension adds a new tab to all products in admin panel and provides the option to remove the "add-to-cart" button from selected products on frontend and allow you to display a custom text snippet of your choice instead of price (like: Call for price).</description>
11
+ <notes>Initial release.</notes>
12
+ <authors><author><name>Damir Perkosan</name><user>dperkosan</user><email>dperkosan@gmail.com</email></author></authors>
13
+ <date>2014-10-01</date>
14
+ <time>13:46:13</time>
15
+ <contents><target name="magecommunity"><dir name="Naya"><dir name="CallForPrice"><dir name="Block"><dir name="Checkout"><dir name="Cart"><file name="Crosssell.php" hash="455b10896a39cff3a969777e65e84c6f"/></dir></dir></dir><dir name="Model"><file name="Observer.php" hash="a0367df6fdd2010728ee66177ebe8cb1"/><dir name="Resource"><file name="Setup.php" hash="06154b7a2d43db45b79f65708c06652a"/></dir></dir><dir name="etc"><file name="config.xml" hash="d5c837c875cf0a1a56f6f967f074386e"/></dir><dir name="sql"><dir name="naya_callforprice_setup"><file name="install-1.0.0.php" hash="8a42355fd977b86b030f9ebae9075a80"/></dir></dir></dir></dir></target><target name="magelocale"><dir><dir name="en_US"><file name="Naya_CallForPrice.csv" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Naya_CallForPrice.xml" hash="a26f9ce37c375f654b16539eddb2cf9f"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="naya_callforprice.xml" hash="c570a0da2f733cf8016ce44972000bcf"/></dir><dir name="template"><dir name="naya"><dir name="callforprice"><file name="nodisplay.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="price.phtml" hash="9bc512314a727a51b335e658499d9558"/></dir></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="js"><dir name="naya"><dir name="callforprice"><file name="callforprice.js" hash="d3d0817d8fa033a4506d68efe5262f2a"/></dir></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>
skin/frontend/base/default/js/naya/callforprice/callforprice.js ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var callforprice = {
2
+ removeButton : function() {
3
+ document.observe("dom:loaded", function() {
4
+ $$('button').each(function(buttonObject) {
5
+ var removeCart = buttonObject.readAttribute('onclick');
6
+ if(removeCart !== null){
7
+ if (removeCart.indexOf("remove-add-to-cart") > -1){
8
+ buttonObject.remove();
9
+ }
10
+ }
11
+ });
12
+ $$('span.remove-unavailable-tag').each(function(removeTag) {
13
+ var removeTagElement = removeTag.next('p.out-of-stock');
14
+ if(removeTagElement !== null && removeTagElement !== undefined){
15
+ removeTagElement.remove();
16
+ }
17
+ removeTag.remove();
18
+ });
19
+ });
20
+ }
21
+ };
22
+
23
+ callforprice.removeButton();
24
+
25
+