addwish - Version 0.20.0

Version Notes

New multisite module

Download this release

Release Info

Developer addwish
Extension addwish
Version 0.20.0
Comparing to
See all releases


Code changes from version 0.19.3 to 0.20.0

app/code/local/Addwish/Awext/Helper/Data.php CHANGED
@@ -2,7 +2,6 @@
2
 
3
  class Addwish_Awext_Helper_Data extends Mage_Core_Helper_Abstract
4
  {
5
-
6
  public function getProductData($product, $extraAttributes = array()) {
7
  $data = array();
8
 
@@ -26,7 +25,11 @@ class Addwish_Awext_Helper_Data extends Mage_Core_Helper_Abstract
26
  $data['currency'] = Mage::app()->getStore()->getCurrentCurrencyCode();
27
  $data['hierarchies'] = $this->getProductHierarchies($product);
28
  $data['brand'] = $product->getData('brand');
29
- $data['instock'] = $this->getProductInStock($product);
 
 
 
 
30
 
31
  if($product->getData('gender')) {
32
  $attr = $product->getResource()->getAttribute("gender");
@@ -57,10 +60,10 @@ class Addwish_Awext_Helper_Data extends Mage_Core_Helper_Abstract
57
 
58
  public function getProductPrice($product, $discountPrice = false) {
59
  if($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED) {
60
- $p = $this->cheapestProductFromGroup($product);
61
- if (isset($p)) {
62
- $product = $p;
63
- }
64
  }
65
 
66
  if ($discountPrice) {
@@ -76,80 +79,116 @@ class Addwish_Awext_Helper_Data extends Mage_Core_Helper_Abstract
76
  }
77
 
78
  private function cheapestProductFromGroup($product) {
79
- $cheapest = null;
80
- $associated = $product->getTypeInstance(true)->getAssociatedProducts($product);
81
- foreach ($associated as $p) {
82
- if ($cheapest == null || $cheapest->getFinalPrice() > $p->getFinalPrice()) {
83
- $cheapest = $p;
84
- }
85
- }
86
- return $cheapest;
87
- }
88
 
89
 
90
  public function getProductHierarchies($product) {
91
  $cats = $product->getCategoryIds();
 
92
 
93
- // Remove category id's that are parent of others
94
- $whiteList = array();
95
- foreach ($cats as $categoryId) {
96
- $category = Mage::getModel('catalog/category')->load($categoryId);
97
- $parentCategories = $category->getParentCategories();
98
- foreach ($parentCategories as $parent) {
99
- $whiteList[] = $parent->getId();
100
- if($categoryId == $parent->getId()) {
101
- continue;
102
- }
103
-
104
- $key = array_search($parent->getId(),$cats);
105
- if($key !== false) {
106
- unset($cats[$key]);
107
  }
108
  }
109
- }
110
-
111
- $hierarchies = array();
112
- foreach ($cats as $categoryId) {
113
- $category = Mage::getModel('catalog/category')->load($categoryId);
114
- $hierarchy = $this->getParentCategory($category, $whiteList);
115
- if(count($hierarchy) > 0) {
116
- $hierarchies[] = $hierarchy;
 
 
 
117
  }
118
  }
119
  return $hierarchies;
120
  }
121
 
122
- private function getParentCategory($category, $whiteList) {
123
- $parent = $category->getParentCategory();
124
- if($parent->getParentId()) {
125
- $list = $this->getParentCategory($parent, $whiteList);
126
- } else {
127
- $list = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  }
129
- if(in_array($category->getId(), $whiteList)) {
130
- $name = trim($category->getName());
131
- if($name != "") {
132
- $list[] = $name;
 
 
 
 
 
 
 
 
 
133
  }
134
  }
135
- return $list;
 
 
 
 
 
 
136
  }
137
 
138
- public function getProductInStock($product) {
139
- $inStock = false;
140
  if($product->isConfigurable()) {
141
  $allProducts = $product->getTypeInstance(true)->getUsedProducts(null, $product);
142
- foreach ($allProducts as $productD) {
143
- if (!$productD->isSaleable() || $productD->getIsInStock() == 0) {
144
- //out of stock for check child simple product
145
- } else {
146
  $inStock = true;
 
147
  }
148
  }
 
149
  } else {
150
- $inStock = $product->isInStock();
 
 
 
 
 
151
  }
152
- return $inStock;
153
  }
154
 
155
- }
2
 
3
  class Addwish_Awext_Helper_Data extends Mage_Core_Helper_Abstract
4
  {
 
5
  public function getProductData($product, $extraAttributes = array()) {
6
  $data = array();
7
 
25
  $data['currency'] = Mage::app()->getStore()->getCurrentCurrencyCode();
26
  $data['hierarchies'] = $this->getProductHierarchies($product);
27
  $data['brand'] = $product->getData('brand');
28
+ $stockInfo = $this->getProductStockInfo($product);
29
+ $data['instock'] = $stockInfo['inStock'];
30
+ $data['qty'] = $stockInfo['qty'];
31
+ $data['visibility'] = $product->getVisibility();
32
+
33
 
34
  if($product->getData('gender')) {
35
  $attr = $product->getResource()->getAttribute("gender");
60
 
61
  public function getProductPrice($product, $discountPrice = false) {
62
  if($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED) {
63
+ $p = $this->cheapestProductFromGroup($product);
64
+ if (isset($p)) {
65
+ $product = $p;
66
+ }
67
  }
68
 
69
  if ($discountPrice) {
79
  }
80
 
81
  private function cheapestProductFromGroup($product) {
82
+ $cheapest = null;
83
+ $associated = $product->getTypeInstance(true)->getAssociatedProducts($product);
84
+ foreach ($associated as $p) {
85
+ if ($cheapest == null || $cheapest->getFinalPrice() > $p->getFinalPrice()) {
86
+ $cheapest = $p;
87
+ }
88
+ }
89
+ return $cheapest;
90
+ }
91
 
92
 
93
  public function getProductHierarchies($product) {
94
  $cats = $product->getCategoryIds();
95
+ $categoryData = $this->getCategoryData();
96
 
97
+ $hierarchies = array();
98
+ $cats = array_unique($cats);
99
+ foreach($cats as $i) {
100
+ $inOther = false;
101
+ foreach($cats as $j) {
102
+ if(in_array($i, $categoryData['parentCategories'][$j])) {
103
+ $inOther = true;
104
+ break;
 
 
 
 
 
 
105
  }
106
  }
107
+ if(!$inOther) {
108
+ $hierarchy = array();
109
+ $current = $i;
110
+ while(isset($categoryData['parentForCategory'][$current])) {
111
+ $next = $categoryData['parentForCategory'][$current];
112
+ $hierarchy[] = $categoryData['categoryName'][$current];
113
+ $current = $next;
114
+ }
115
+ if(count($hierarchy) > 0) {
116
+ $hierarchies[] = array_reverse($hierarchy);
117
+ }
118
  }
119
  }
120
  return $hierarchies;
121
  }
122
 
123
+ private static $_categoryData = null;
124
+ private function getCategoryData() {
125
+
126
+ if($this->_categoryData != null) {
127
+ return $this->_categoryData;
128
+ }
129
+ $root = Mage::app()->getStore()->getRootCategoryId();
130
+
131
+ $categories = Mage::getModel('catalog/category')
132
+ ->getCollection()
133
+ ->addAttributeToSelect('entity_id')
134
+ ->addAttributeToSelect('name')
135
+ ->addAttributeToSelect('parent_id')
136
+ ->addIsActiveFilter();
137
+
138
+ $parentForCategory = array();
139
+ $categoryName = array();
140
+ foreach($categories as $cat){
141
+ if($cat->entity_id == $root) {
142
+ continue;
143
+ }
144
+ $parentForCategory[$cat->entity_id] = $cat->parent_id;
145
+ $categoryName[$cat->entity_id] = $cat->name;
146
  }
147
+
148
+ $parentList = array();
149
+ foreach($categories as $cat){
150
+ if($cat->entity_id == $root) {
151
+ continue;
152
+ }
153
+ $parentForCategory[$cat->entity_id] = $cat->parent_id;
154
+ $parentList[$cat->entity_id] = array();
155
+ $i = $cat->entity_id;
156
+ while(isset($parentForCategory[$i])) {
157
+ $next = $parentForCategory[$i];
158
+ $parentList[$cat->entity_id][] = $next;
159
+ $i = $next;
160
  }
161
  }
162
+
163
+ $this->_categoryData = array(
164
+ 'parentCategories' => $parentList,
165
+ 'parentForCategory' => $parentForCategory,
166
+ 'categoryName' => $categoryName
167
+ );
168
+ return $this->_categoryData;
169
  }
170
 
171
+ public function getProductStockInfo($product) {
172
+
173
  if($product->isConfigurable()) {
174
  $allProducts = $product->getTypeInstance(true)->getUsedProducts(null, $product);
175
+ $inStock = false;
176
+ foreach ($allProducts as $p) {
177
+ $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($p);
178
+ if ($p->isSaleable() && $stock->getIsInStock() != 0) {
179
  $inStock = true;
180
+ break;
181
  }
182
  }
183
+ return array('inStock' => $inStock, 'qty' => $stock ? $stock->getQty() : 0);
184
  } else {
185
+ $inStock = false;
186
+ $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
187
+ if ($product->isSaleable() && $stock->getIsInStock() != 0) {
188
+ $inStock = true;
189
+ }
190
+ return array('inStock' => $inStock, 'qty' => $stock->getQty());
191
  }
 
192
  }
193
 
194
+ }
app/code/local/Addwish/Awext/controllers/IndexController.php CHANGED
@@ -192,7 +192,7 @@ class Addwish_Awext_IndexController extends Mage_Core_Controller_Front_Action
192
  ->getCollection()
193
  ->addWebsiteFilter(array(Mage::app()->getStore()->getWebsiteId()))
194
  ->addStoreFilter(Mage::app()->getStore()->getStoreId())
195
- ->addAttributeToFilter('visibility', 4)
196
  ->addAttributeToSelect('*')
197
  ->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED));
198
 
192
  ->getCollection()
193
  ->addWebsiteFilter(array(Mage::app()->getStore()->getWebsiteId()))
194
  ->addStoreFilter(Mage::app()->getStore()->getStoreId())
195
+ ->addAttributeToFilter('visibility', array('neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE))
196
  ->addAttributeToSelect('*')
197
  ->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED));
198
 
app/code/local/Addwish/Awext/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Addwish_Awext>
5
- <version>0.19.3</version>
6
  </Addwish_Awext>
7
  </modules>
8
  <frontend>
2
  <config>
3
  <modules>
4
  <Addwish_Awext>
5
+ <version>0.20.0</version>
6
  </Addwish_Awext>
7
  </modules>
8
  <frontend>
app/design/frontend/base/default/template/addwish/product-span.phtml CHANGED
@@ -1,6 +1,8 @@
1
  <?php
2
  $product = Mage::registry('current_product');
3
  $productData = Mage::helper('awext')->getProductData($product);
 
 
4
 
5
  $parts=explode("uenc/", Mage::helper('checkout/cart')->getAddUrl($product));
6
  $parts=explode("/product",$parts[1]);
1
  <?php
2
  $product = Mage::registry('current_product');
3
  $productData = Mage::helper('awext')->getProductData($product);
4
+ unset($productData['qty']);
5
+ unset($productData['visibility']);
6
 
7
  $parts=explode("uenc/", Mage::helper('checkout/cart')->getAddUrl($product));
8
  $parts=explode("/product",$parts[1]);
package.xml CHANGED
@@ -1,2 +1,2 @@
1
  <?xml version="1.0"?>
2
- <package><name>addwish</name><version>0.19.3</version><stability>stable</stability><license>GNU General Public License (GPL)</license><channel>community</channel><extends></extends><summary>New multisite module</summary><description>New multisite module</description><notes>New multisite module</notes><authors><author><name>addwish</name><user>addwish</user><email>krj@addwish.com</email></author></authors><date>2017-03-08</date><time>0:36:51</time><compatible></compatible><dependencies><required><php><min>5.2.0</min><max>8.0.0</max></php></required></dependencies><contents><target name="mage"><dir name="app"><dir name="code"><dir name="local"><dir name="Addwish"><dir name="Awext"><dir name="Block"><dir name="Adminhtml"><dir name="Awext"><file name="View.php" hash="a5a5aa835bdbaf1102b50e90dec526a8"/><dir name="View"><file name="Tabs.php" hash="b68e152475528d168d92ca6e8ad6eafc"/><dir name="Tab"><file name="Details.php" hash="eff51a28eacafbe07577af60237ad9c4"/><file name="Recommend.php" hash="02d71705312a1de1da6445027bb0926d"/><file name="Search.php" hash="c94f0146c7529f0542100a871446c4f0"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="IndexController.php" hash="fe9d4e15455eddce03398994123fb9b1"/><dir name="Adminhtml"><file name="AwextController.php" hash="abf8b0b390b17add398d3af44e394d91"/></dir></dir><dir name="etc"><file name="config.xml" hash="c42392babec2997d020fc3dcbc098f5c"/></dir><dir name="Helper"><file name="Data.php" hash="42def56b0f85e51c0d27427a44d430b1"/></dir><dir name="Model"><file name="Awext.php" hash="1925cb6fd94cc7cd6baecda71964a424"/><file name="Observer.php" hash="510c80ff97a3d611f1f6bb9b54d486bb"/><dir name="Mysql4"><file name="Awext.php" hash="acd112233e367ebe80caf114f5dfe653"/><dir name="Awext"><file name="Collection.php" hash="12afe62372c67a5bd9154695c8d095f3"/></dir></dir></dir><dir name="sql"><dir name="addwish_setup"><file name="mysql4-install-0.0.4.php" hash="77a5d3d50380396c9bd2a9dfdfea8905"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="awext.xml" hash="b632bf4a38cfb992303f97cd7a449a15"/></dir><dir name="template"><dir name="awext"><file name="list.phtml" hash="5eedadcd2400f296b7ff3a77823cc4e4"/><file name="recommendations.phtml" hash="f8e63393c235903babd5a27a68b4a054"/><file name="search.phtml" hash="82d7130e256b0689d3b1682bf097fa55"/><file name="store-selector.phtml" hash="275b91522d136265f22de6550c7ca6dc"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="awext.xml" hash="d9e749008e9d97afd7b75855857a18b3"/></dir><dir name="template"><dir name="addwish"><file name="addwish-head.phtml" hash="c5b6fa2cae55ad1ddd4a5c64f8d532f6"/><file name="basket-span.phtml" hash="e94f8c7f460ab66e3906fcc0e3fdf76b"/><file name="conversion-span.phtml" hash="0d9368e73977b4e9c1c0fb00d34cb01c"/><file name="integrator.phtml" hash="0a41e4e5c3f63f05dfce43040e52dd53"/><file name="product-span.phtml" hash="4d2e243368b2ece3f8126400bdce6413"/><file name="search-result-page.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="upsells-page.phtml" hash="ac41002da8c7bb57233599a00053ef77"/></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Addwish_Awext.xml" hash="fea2883f86536f249670eea31980f72c"/></dir></dir></dir><dir name="skin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="css"><file name="addwish.css" hash="df6e33a58cf2381ceaba72253a29796d"/></dir><dir name="images"><dir name="addwish"><file name="addwish.png" hash="a588d24d1919d9206eff40a886b88ef1"/></dir></dir></dir></dir></dir></dir></target></contents></package>
1
  <?xml version="1.0"?>
2
+ <package><name>addwish</name><version>0.20.0</version><stability>stable</stability><license>GNU General Public License (GPL)</license><channel>community</channel><extends></extends><summary>New multisite module</summary><description>New multisite module</description><notes>New multisite module</notes><authors><author><name>addwish</name><user>addwish</user><email>krj@addwish.com</email></author></authors><date>2017-04-06</date><time>5:48:31</time><compatible></compatible><dependencies><required><php><min>5.2.0</min><max>8.0.0</max></php></required></dependencies><contents><target name="mage"><dir name="app"><dir name="code"><dir name="local"><dir name="Addwish"><dir name="Awext"><dir name="Block"><dir name="Adminhtml"><dir name="Awext"><file name="View.php" hash="a5a5aa835bdbaf1102b50e90dec526a8"/><dir name="View"><file name="Tabs.php" hash="b68e152475528d168d92ca6e8ad6eafc"/><dir name="Tab"><file name="Details.php" hash="eff51a28eacafbe07577af60237ad9c4"/><file name="Recommend.php" hash="02d71705312a1de1da6445027bb0926d"/><file name="Search.php" hash="c94f0146c7529f0542100a871446c4f0"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="IndexController.php" hash="c777dfcbb9c8af630f0a9202b2463f47"/><dir name="Adminhtml"><file name="AwextController.php" hash="abf8b0b390b17add398d3af44e394d91"/></dir></dir><dir name="etc"><file name="config.xml" hash="22a2e7698784513966dbe970827441f0"/></dir><dir name="Helper"><file name="Data.php" hash="5e87f59f899042deb77c00e67555cf5b"/></dir><dir name="Model"><file name="Awext.php" hash="1925cb6fd94cc7cd6baecda71964a424"/><file name="Observer.php" hash="510c80ff97a3d611f1f6bb9b54d486bb"/><dir name="Mysql4"><file name="Awext.php" hash="acd112233e367ebe80caf114f5dfe653"/><dir name="Awext"><file name="Collection.php" hash="12afe62372c67a5bd9154695c8d095f3"/></dir></dir></dir><dir name="sql"><dir name="addwish_setup"><file name="mysql4-install-0.0.4.php" hash="77a5d3d50380396c9bd2a9dfdfea8905"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="awext.xml" hash="b632bf4a38cfb992303f97cd7a449a15"/></dir><dir name="template"><dir name="awext"><file name="list.phtml" hash="5eedadcd2400f296b7ff3a77823cc4e4"/><file name="recommendations.phtml" hash="f8e63393c235903babd5a27a68b4a054"/><file name="search.phtml" hash="82d7130e256b0689d3b1682bf097fa55"/><file name="store-selector.phtml" hash="275b91522d136265f22de6550c7ca6dc"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="awext.xml" hash="d9e749008e9d97afd7b75855857a18b3"/></dir><dir name="template"><dir name="addwish"><file name="addwish-head.phtml" hash="c5b6fa2cae55ad1ddd4a5c64f8d532f6"/><file name="basket-span.phtml" hash="e94f8c7f460ab66e3906fcc0e3fdf76b"/><file name="conversion-span.phtml" hash="0d9368e73977b4e9c1c0fb00d34cb01c"/><file name="integrator.phtml" hash="0a41e4e5c3f63f05dfce43040e52dd53"/><file name="product-span.phtml" hash="690c67739d6d4ad49c48a21939c1ab4f"/><file name="search-result-page.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="upsells-page.phtml" hash="ac41002da8c7bb57233599a00053ef77"/></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Addwish_Awext.xml" hash="fea2883f86536f249670eea31980f72c"/></dir></dir></dir><dir name="skin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="css"><file name="addwish.css" hash="df6e33a58cf2381ceaba72253a29796d"/></dir><dir name="images"><dir name="addwish"><file name="addwish.png" hash="a588d24d1919d9206eff40a886b88ef1"/></dir></dir></dir></dir></dir></dir></target></contents></package>