NowInStore_CatalogBuilder - Version 1.2.0

Version Notes

Fix issue with rounded prices
Added wholesale price

Download this release

Release Info

Developer Kwaku
Extension NowInStore_CatalogBuilder
Version 1.2.0
Comparing to
See all releases


Code changes from version 1.1.1 to 1.2.0

app/code/community/NowInStore/CatalogBuilder/controllers/CategoriesController.php CHANGED
@@ -1,6 +1,10 @@
1
  <?php
2
  class NowInStore_CatalogBuilder_CategoriesController extends Mage_Core_Controller_Front_Action
3
  {
 
 
 
 
4
  public function indexAction()
5
  {
6
  $category_collection = Mage::getModel('catalog/category')
@@ -9,13 +13,10 @@ class NowInStore_CatalogBuilder_CategoriesController extends Mage_Core_Controlle
9
  ->addIsActiveFilter();
10
  $categories = array();
11
  foreach($category_collection as $category) {
12
- $children = $category->getChildrenCategories()->toArray();
13
- if (count($children) == 0) {
14
- array_push($categories, array(
15
- "id" => $category->getId(),
16
- "name" => $category->getName()
17
- ));
18
- }
19
  }
20
  $jsonData = json_encode($categories);
21
  $this->getResponse()->setHeader('Content-type', 'application/json');
1
  <?php
2
  class NowInStore_CatalogBuilder_CategoriesController extends Mage_Core_Controller_Front_Action
3
  {
4
+ public function addCategories(&$categories, $category_collection) {
5
+
6
+
7
+ }
8
  public function indexAction()
9
  {
10
  $category_collection = Mage::getModel('catalog/category')
13
  ->addIsActiveFilter();
14
  $categories = array();
15
  foreach($category_collection as $category) {
16
+ array_push($categories, array(
17
+ "id" => $category->getId(),
18
+ "name" => $category->getName()
19
+ ));
 
 
 
20
  }
21
  $jsonData = json_encode($categories);
22
  $this->getResponse()->setHeader('Content-type', 'application/json');
app/code/community/NowInStore/CatalogBuilder/controllers/CategoriesController.php~ ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class NowInStore_CatalogBuilder_CategoriesController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function indexAction()
5
+ {
6
+ $category_collection = Mage::getModel('catalog/category')
7
+ ->getCollection()
8
+ ->addAttributeToSelect('*')
9
+ ->addIsActiveFilter();
10
+ $categories = array();
11
+ foreach($category_collection as $category) {
12
+ $children = $category->getChildrenCategories()->toArray();
13
+ if (count($children) == 0) {
14
+ array_push($categories, array(
15
+ "id" => $category->getId(),
16
+ "name" => $category->getName()
17
+ ));
18
+ }
19
+ }
20
+ $jsonData = json_encode($categories);
21
+ $this->getResponse()->setHeader('Content-type', 'application/json');
22
+ $this->getResponse()->setBody($jsonData);
23
+ }
24
+ }
app/code/community/NowInStore/CatalogBuilder/controllers/ProductsController.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  class NowInStore_CatalogBuilder_ProductsController extends Mage_Core_Controller_Front_Action
3
  {
4
  public function indexAction()
@@ -8,28 +9,35 @@ class NowInStore_CatalogBuilder_ProductsController extends Mage_Core_Controller_
8
  $page = 1;
9
  }
10
  $product_collection = Mage::getModel('catalog/product')
11
- ->getCollection()
12
  // ->addAttributeToFilter('is_active', 1)
13
- ->addExpressionAttributeToSelect('lower_name', 'LOWER({{name}})', array('name'))
14
- ->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
15
- ->setPageSize(50)
16
- ->setCurPage($page)
17
- ->addAttributeToSelect(array('id', 'name', 'sku', 'price', 'image', 'description'));
18
 
19
- $keywords = $_GET['keywords'];
20
  if (!empty ($keywords)) {
21
- $product_collection = $product_collection->addAttributeToFilter('lower_name', array('like' => '%'.strtolower($keywords).'%'));
22
  }
23
 
24
- $category_id = $_GET['category_id'];
25
  if (!empty ($category_id)) {
26
  $product_collection = $product_collection
27
- ->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
28
  ->addAttributeToFilter('category_id', array('in' => $category_id));
29
  }
30
  $products = array();
31
  $currency = Mage::app()->getStore()->getCurrentCurrencyCode();
32
- foreach($product_collection as $product) {
 
 
 
 
 
 
 
33
  if ($product->isConfigurable()) {
34
  $productAttributeOptions = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);
35
  }
@@ -41,41 +49,58 @@ class NowInStore_CatalogBuilder_ProductsController extends Mage_Core_Controller_
41
  $attributeOptions[$label][$valueIndex] = $attribute['store_label'];
42
  }
43
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  array_push($products, array(
45
- "id" => $product->getId(),
46
- "title" => $product->getName(),
47
- "sku" => $product->getSku(),
48
- "price" => intval($product->getPrice()),
49
- "main_image" => $product->getImageUrl(),
50
- "description" => $product->getDescription(),
51
- "thumbnail_image" => (string)Mage::helper('catalog/image')->init($product, 'image')->resize(75),
52
- "iso_currency_code" => $currency,
53
- "url" => $product->getProductUrl(),
54
- "variations" => $attributeOptions
 
 
55
  ));
56
  }
57
  $jsonData = json_encode($products);
58
  $this->getResponse()->setHeader('Content-type', 'application/json');
59
  $this->getResponse()->setBody($jsonData);
60
  }
 
61
  public function countAction()
62
  {
63
  $product_collection = Mage::getModel('catalog/product')
64
- ->getCollection()
65
  // ->addAttributeToFilter('is_active', 1)
66
- ->addExpressionAttributeToSelect('lower_name', 'LOWER({{name}})', array('name'))
67
- ->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
68
- ->addAttributeToSelect(array('id', 'name', 'sku', 'price', 'image'));
69
 
70
- $query = $_GET['query'];
71
  if (!empty ($query)) {
72
- $product_collection = $product_collection->addAttributeToFilter('lower_name', array('like' => '%'.strtolower($query).'%'));
73
  }
74
 
75
- $category_id = $_GET['category_id'];
76
  if (!empty ($category_id)) {
77
  $product_collection = $product_collection
78
- ->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
79
  ->addAttributeToFilter('category_id', array('in' => $category_id));
80
  }
81
  $jsonData = json_encode(array("count" => $product_collection->count()));
1
  <?php
2
+
3
  class NowInStore_CatalogBuilder_ProductsController extends Mage_Core_Controller_Front_Action
4
  {
5
  public function indexAction()
9
  $page = 1;
10
  }
11
  $product_collection = Mage::getModel('catalog/product')
12
+ ->getCollection()
13
  // ->addAttributeToFilter('is_active', 1)
14
+ ->addExpressionAttributeToSelect('lower_name', 'LOWER({{name}})', array('name'))
15
+ ->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
16
+ ->setPageSize(50)
17
+ ->setCurPage($page)
18
+ ->addAttributeToSelect(array('id', 'name', 'sku', 'price', 'group_price', 'image', 'description'));
19
 
20
+ $keywords = $_GET['keywords'];
21
  if (!empty ($keywords)) {
22
+ $product_collection = $product_collection->addAttributeToFilter('lower_name', array('like' => '%' . strtolower($keywords) . '%'));
23
  }
24
 
25
+ $category_id = $_GET['category_id'];
26
  if (!empty ($category_id)) {
27
  $product_collection = $product_collection
28
+ ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
29
  ->addAttributeToFilter('category_id', array('in' => $category_id));
30
  }
31
  $products = array();
32
  $currency = Mage::app()->getStore()->getCurrentCurrencyCode();
33
+ $group_collection = Mage::getModel('customer/group')->getCollection();
34
+ $wholesaleGroup = null;
35
+ foreach ($group_collection as $group) {
36
+ if ($group->getCode() === 'Wholesale') {
37
+ $wholesaleGroup = $group;
38
+ }
39
+ }
40
+ foreach ($product_collection as $product) {
41
  if ($product->isConfigurable()) {
42
  $productAttributeOptions = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);
43
  }
49
  $attributeOptions[$label][$valueIndex] = $attribute['store_label'];
50
  }
51
  }
52
+ $price = floatval($product->getPrice());
53
+ $wholesalePrice = 0;
54
+ $product->setCustomerGroupId($wholesaleGroup->getId());
55
+ $groupPrices = $product->getGroupPrice();
56
+ if (is_null($groupPrices)) {
57
+ $attribute = $product->getResource()->getAttribute('group_price');
58
+ if ($attribute) {
59
+ $attribute->getBackend()->afterLoad($product);
60
+ $groupPrices = $product->getData('group_price');
61
+ }
62
+ }
63
+ if (!is_null($groupPrices) || is_array($groupPrices)) {
64
+ $wholesalePrice = $groupPrices;
65
+ }
66
  array_push($products, array(
67
+ "id" => $product->getId(),
68
+ "title" => $product->getName(),
69
+ "sku" => $product->getSku(),
70
+ "price" => $price,
71
+ "wholesale_price" => floatval($wholesalePrice),
72
+ "main_image" => $product->getImageUrl(),
73
+ "description" => $product->getDescription(),
74
+ "thumbnail_image" => (string)Mage::helper('catalog/image')->init($product, 'image')->resize(75),
75
+ "iso_currency_code" => $currency,
76
+ "g" => $wholesaleGroup->getId(),
77
+ "url" => $product->getProductUrl(),
78
+ "variations" => $attributeOptions
79
  ));
80
  }
81
  $jsonData = json_encode($products);
82
  $this->getResponse()->setHeader('Content-type', 'application/json');
83
  $this->getResponse()->setBody($jsonData);
84
  }
85
+
86
  public function countAction()
87
  {
88
  $product_collection = Mage::getModel('catalog/product')
89
+ ->getCollection()
90
  // ->addAttributeToFilter('is_active', 1)
91
+ ->addExpressionAttributeToSelect('lower_name', 'LOWER({{name}})', array('name'))
92
+ ->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
93
+ ->addAttributeToSelect(array('id', 'name', 'sku', 'price', 'image'));
94
 
95
+ $query = $_GET['query'];
96
  if (!empty ($query)) {
97
+ $product_collection = $product_collection->addAttributeToFilter('lower_name', array('like' => '%' . strtolower($query) . '%'));
98
  }
99
 
100
+ $category_id = $_GET['category_id'];
101
  if (!empty ($category_id)) {
102
  $product_collection = $product_collection
103
+ ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
104
  ->addAttributeToFilter('category_id', array('in' => $category_id));
105
  }
106
  $jsonData = json_encode(array("count" => $product_collection->count()));
app/code/community/NowInStore/CatalogBuilder/controllers/ProductsController.php~ ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class NowInStore_CatalogBuilder_ProductsController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function indexAction()
5
+ {
6
+ $page = $_GET['page'];
7
+ if (empty($page)) {
8
+ $page = 1;
9
+ }
10
+ $product_collection = Mage::getModel('catalog/product')
11
+ ->getCollection()
12
+ // ->addAttributeToFilter('is_active', 1)
13
+ ->addExpressionAttributeToSelect('lower_name', 'LOWER({{name}})', array('name'))
14
+ ->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
15
+ ->setPageSize(50)
16
+ ->setCurPage($page)
17
+ ->addAttributeToSelect(array('id', 'name', 'sku', 'price', 'group_price', 'image', 'description'));
18
+
19
+ $keywords = $_GET['keywords'];
20
+ if (!empty ($keywords)) {
21
+ $product_collection = $product_collection->addAttributeToFilter('lower_name', array('like' => '%'.strtolower($keywords).'%'));
22
+ }
23
+
24
+ $category_id = $_GET['category_id'];
25
+ if (!empty ($category_id)) {
26
+ $product_collection = $product_collection
27
+ ->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
28
+ ->addAttributeToFilter('category_id', array('in' => $category_id));
29
+ }
30
+ $products = array();
31
+ $currency = Mage::app()->getStore()->getCurrentCurrencyCode();
32
+ $group_collection = Mage::getModel('customer/group')->getCollection();
33
+ $wholesaleGroup = null;
34
+ foreach($group_collection as $group) {
35
+ $wholesaleGroup .= $group->getName();
36
+ if ($group['name'] === 'wholesale') {
37
+ }
38
+ }
39
+ foreach($product_collection as $product) {
40
+ if ($product->isConfigurable()) {
41
+ $productAttributeOptions = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);
42
+ }
43
+ $attributeOptions = array();
44
+ foreach ($productAttributeOptions as $productAttribute) {
45
+ foreach ($productAttribute['values'] as $attribute) {
46
+ $label = $productAttribute['label'];
47
+ $valueIndex = $attribute['value_index'];
48
+ $attributeOptions[$label][$valueIndex] = $attribute['store_label'];
49
+ }
50
+ }
51
+ $price = floatval($product->getPrice());
52
+ $wholesalePrice = 0;
53
+ $groupPrices = $product->getGroupPrice();
54
+ if (is_null($groupPrices)) {
55
+ $attribute = $product->getResource()->getAttribute('group_price');
56
+ if ($attribute){
57
+ $attribute->getBackend()->afterLoad($product);
58
+ $groupPrices = $product->getData('group_price');
59
+ }
60
+ }
61
+ if (!is_null($groupPrices) || is_array($groupPrices)) {
62
+ $wholesalePrice = $groupPrices;
63
+ }
64
+ array_push($products, array(
65
+ "id" => $product->getId(),
66
+ "title" => $product->getName(),
67
+ "sku" => $product->getSku(),
68
+ "price" => $price,
69
+ "wholesale_price" => $wholesalePrice,
70
+ "main_image" => $product->getImageUrl(),
71
+ "description" => $product->getDescription(),
72
+ "thumbnail_image" => (string)Mage::helper('catalog/image')->init($product, 'image')->resize(75),
73
+ "iso_currency_code" => $currency,
74
+ "g" => $wholesaleGroup,
75
+ "url" => $product->getProductUrl(),
76
+ "variations" => $attributeOptions
77
+ ));
78
+ }
79
+ $jsonData = json_encode($products);
80
+ $this->getResponse()->setHeader('Content-type', 'application/json');
81
+ $this->getResponse()->setBody($jsonData);
82
+ }
83
+ public function countAction()
84
+ {
85
+ $product_collection = Mage::getModel('catalog/product')
86
+ ->getCollection()
87
+ // ->addAttributeToFilter('is_active', 1)
88
+ ->addExpressionAttributeToSelect('lower_name', 'LOWER({{name}})', array('name'))
89
+ ->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
90
+ ->addAttributeToSelect(array('id', 'name', 'sku', 'price', 'image'));
91
+
92
+ $query = $_GET['query'];
93
+ if (!empty ($query)) {
94
+ $product_collection = $product_collection->addAttributeToFilter('lower_name', array('like' => '%'.strtolower($query).'%'));
95
+ }
96
+
97
+ $category_id = $_GET['category_id'];
98
+ if (!empty ($category_id)) {
99
+ $product_collection = $product_collection
100
+ ->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
101
+ ->addAttributeToFilter('category_id', array('in' => $category_id));
102
+ }
103
+ $jsonData = json_encode(array("count" => $product_collection->count()));
104
+ $this->getResponse()->setHeader('Content-type', 'application/json');
105
+ $this->getResponse()->setBody($jsonData);
106
+ }
107
+ }
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>NowInStore_CatalogBuilder</name>
4
- <version>1.1.1</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
@@ -12,11 +12,12 @@
12
  Our blog and online-chat experts are on hand that share tips and tricks on how you can use catalogs and flyers to grow your sales. &#xD;
13
  &#xD;
14
  With a few clicks, import all of your Magento products into a beautiful drag and drop interface. Easily choose and organize each page of your catalog or flyer, use different layouts, customize your front and back covers and add a wholesale contract and order forms.</description>
15
- <notes>Repackaging</notes>
 
16
  <authors><author><name>Kwaku</name><user>Zigah</user><email>kwaku.zigah@nowinstore.com</email></author></authors>
17
- <date>2016-05-25</date>
18
- <time>21:22:13</time>
19
- <contents><target name="magecommunity"><dir name="NowInStore"><dir name="CatalogBuilder"><dir name="controllers"><file name="AuthController.php" hash="083a894900d82e353543cd762da9e157"/><file name="CategoriesController.php" hash="abc588a995c3c8797b824e0c04c57295"/><file name="ProductsController.php" hash="c2a8b30a4f6c92bd87c25365f18b8b42"/><file name="ProfileController.php" hash="f720bea41f8a18d7296d91a81f4a4722"/></dir><dir name="etc"><file name="adminhtml.xml" hash="3d7e6a6f47a3a37945603d5620a49c22"/><file name="config.xml" hash="b10c591395a3f476f452e06885322d65"/><file name="config.xml~" hash="542bda660e3269cf774df308fd389a19"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="NowInStore_CatalogBuilder.xml" hash="a087b751cea9700fd21fa59bb3d0a666"/></dir></target></contents>
20
  <compatible/>
21
  <dependencies><required><php><min>5.2.0</min><max>5.6.21</max></php></required></dependencies>
22
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>NowInStore_CatalogBuilder</name>
4
+ <version>1.2.0</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
12
  Our blog and online-chat experts are on hand that share tips and tricks on how you can use catalogs and flyers to grow your sales. &#xD;
13
  &#xD;
14
  With a few clicks, import all of your Magento products into a beautiful drag and drop interface. Easily choose and organize each page of your catalog or flyer, use different layouts, customize your front and back covers and add a wholesale contract and order forms.</description>
15
+ <notes>Fix issue with rounded prices&#xD;
16
+ Added wholesale price</notes>
17
  <authors><author><name>Kwaku</name><user>Zigah</user><email>kwaku.zigah@nowinstore.com</email></author></authors>
18
+ <date>2016-06-10</date>
19
+ <time>16:39:00</time>
20
+ <contents><target name="magecommunity"><dir name="NowInStore"><dir name="CatalogBuilder"><dir name="controllers"><file name="AuthController.php" hash="083a894900d82e353543cd762da9e157"/><file name="CategoriesController.php" hash="9e643060ad40ef54c13f2b72f943402b"/><file name="CategoriesController.php~" hash="abc588a995c3c8797b824e0c04c57295"/><file name="ProductsController.php" hash="0493192bbfe5bef8c3b0d312e607a1f0"/><file name="ProductsController.php~" hash="4feb53033fcc499c450917c2c645a0d4"/><file name="ProfileController.php" hash="f720bea41f8a18d7296d91a81f4a4722"/></dir><dir name="etc"><file name="adminhtml.xml" hash="3d7e6a6f47a3a37945603d5620a49c22"/><file name="config.xml" hash="b10c591395a3f476f452e06885322d65"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="NowInStore_CatalogBuilder.xml" hash="a087b751cea9700fd21fa59bb3d0a666"/></dir></target></contents>
21
  <compatible/>
22
  <dependencies><required><php><min>5.2.0</min><max>5.6.21</max></php></required></dependencies>
23
  </package>