Skip to content

Commit

Permalink
move specialised product list method to model
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo187 committed Dec 6, 2013
1 parent a1b54f2 commit 193f063
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
24 changes: 5 additions & 19 deletions controllers/bo/component/ecommerce/recipe_ingredients.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
* Licensed under the New BSD License. See the file LICENSE.txt for details.
*/

require_once('models/ecommerce/ecommerce_recipe_ingredients.php');
require_once('models/ecommerce/ecommerce_product.php');

class Onxshop_Controller_Bo_Component_Ecommerce_Recipe_Ingredients extends Onxshop_Controller {

/**
* main action
*/

public function mainAction() {

require_once('models/ecommerce/ecommerce_recipe_ingredients.php');
require_once('models/ecommerce/ecommerce_product.php');

$Ingredients = new ecommerce_recipe_ingredients();
$Product = new ecommerce_product();

$recipe_id = $this->GET['recipe_id'];

Expand Down Expand Up @@ -67,7 +68,7 @@ public function mainAction() {
* get ingredient list (products)
*/

$products = $this->getProductList();
$products = $Product->getProductListForDropdown();
$this->parseIngredients($products);

/**
Expand Down Expand Up @@ -111,20 +112,5 @@ public function parseIngredients(&$products) {
}
}

public function getProductList()
{
$Product = new ecommerce_product();
$sql = "SELECT v.id AS id,
v.name AS variety_name,
p.name AS product_name,
v.publish AS variety_publish,
p.publish AS product_publish
FROM ecommerce_product_variety AS v
LEFT JOIN ecommerce_product AS p ON p.id = v.product_id
ORDER BY p.name ASC";
$list = $Product->executeSql($sql);
return $list;
}

}

24 changes: 24 additions & 0 deletions models/ecommerce/ecommerce_product.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,25 @@ function getProductVarietyList($product_id) {
return false;
}
}

/**
* get product list for dropdown
*/

function getProductListForDropdown() {

$sql = "SELECT v.id AS id,
v.name AS variety_name,
p.name AS product_name,
v.publish AS variety_publish,
p.publish AS product_publish,
(SELECT src FROM ecommerce_product_image AS i WHERE i.node_id = p.id ORDER BY priority DESC, id ASC LIMIT 1) as image_src
FROM ecommerce_product_variety AS v
LEFT JOIN ecommerce_product AS p ON p.id = v.product_id
ORDER BY p.name ASC";

return $this->executeSql($sql);
}

/**
* get product detail by variety id
Expand Down Expand Up @@ -452,6 +471,11 @@ function getFilteredProductList($filter = null, $currency_code = GLOBAL_DEFAULT_
if ($filter['publish'] === 0 || $filter['disabled'] == 'disabled') $add_to_where .= " AND product.publish = 0";
else if ($filter['publish'] === 1 || $filter['disabled'] == 'enabled') $add_to_where .= " AND product.publish = 1 AND variety.publish = 1";

//specal offer
if (is_numeric($filter['offer_group_id'])) {
$add_to_where .= " AND variety.id IN (SELECT product_variety_id FROM ecommerce_offer WHERE offer_group_id = {$filter['offer_group_id']})";
}

//image role
if ($filter['image_role']) {
$filter['image_role'] = pg_escape_string($filter['image_role']);
Expand Down

0 comments on commit 193f063

Please sign in to comment.