tree - CakePHP, how can I find all products associated with sub categories when parent category given? -


i've got 2 tables setup use tree behavior, manufacturers, , categories.

products can belong 1 category , 1 manufacturer, manufacturers(child) owned other manufacturers(parent), , likewise categories(child) subcategory of another(parent).

i want following:

given category id (parent), find products in subcategories given manufacturer id (parent), find products in child manufacturers

i have tried following (in products controller):

$conditions['product.category_id'] = $this->product->category->children($id,false,'id'); $this->paginate = array(             'conditions' => $conditions,             'limit' => 21         ); $products = $this->paginate('product'); $this->set(compact('products'));     

but gives me this:

 `product`.`category_id` in (array, array, array, array, array, array) 

if print_r can see grabbing information need(see below), how can it, , there better way this?

array ( [product.category_id] => array     (         [0] => array             (                 [category] => array                     (                         [id] => 11                     )              )          [1] => array             (                 [category] => array                     (                         [id] => 12                     )              )          [2] => array             (                 [category] => array                     (                         [id] => 23                     )              )          [3] => array             (                 [category] => array                     (                         [id] => 24                     )              )          [4] => array             (                 [category] => array                     (                         [id] => 25                     )              )          [5] => array             (                 [category] => array                     (                         [id] => 26                     )              )      )  ) 

the query failing because expects array containing only category-ids, this:

$conditions['product.category_id'] = array(1,4,5,6); 

you can achieve 'extracting' values array using hash::extract() (or set::extract() if you're using cakephp 1.3)

$categoryids = $this->product->category->children($id,false,'id');  $conditions['product.category_id'] = hash::extract($categoryids, '{n}.category.id); 

read documentation on hash utility here:

http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html#hash::extract


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -