Skip to main content
added 11 characters in body
Source Link
kK-Storm
  • 492
  • 1
  • 5
  • 20

What I want to ask is is there some possibility to have array which I get by using 'find' model's function ('conditions' => array('Product.id' => $products)) to be sorted not by some of Model.field values (as in 'order' option), but by $products array indices, so that when I render the order contentsproducts content in view I would get all those products in cart sorted in such ordersequence as user addedwere adding them.

What I want to ask is is there some possibility to have array which I get by using 'find' model's function ('conditions' => array('Product.id' => $products)) to be sorted not by some of Model.field values (as in 'order' option), but by $products array indices, so that when I render the order contents in view I would get all those products in cart sorted in such order as user added them.

What I want to ask is is there some possibility to have array which I get by using 'find' model's function ('conditions' => array('Product.id' => $products)) to be sorted not by some of Model.field values (as in 'order' option), but by $products array indices, so that when I render the products content in view I would get all those products in cart sorted in such sequence as user were adding them.

added 417 characters in body
Source Link
kK-Storm
  • 492
  • 1
  • 5
  • 20

So far all the answers doesn't solve my problem. Please, pay closer attention to the example I gave, it's very simple, but the answers provided are in different key.

Again, I need final array $list to be sorted by indices of session array $products, but I get $list sorted by Product.id field, even though I didn't specify any 'find(array('order'=> ...))' at all and even tried to set it to false.

So far all the answers doesn't solve my problem. Please, pay closer attention to the example I gave, it's very simple, but the answers provided are in different key.

Again, I need final array $list to be sorted by indices of session array $products, but I get $list sorted by Product.id field, even though I didn't specify any 'find(array('order'=> ...))' at all and even tried to set it to false.

added 1122 characters in body
Source Link
kK-Storm
  • 492
  • 1
  • 5
  • 20

Using CakePHP 2.0 here. The title is a bit misleading, so to clear things up - I have session array which is populated with ids of products as user adds them to cart. So this array goes like [0] => 25, [1] => 70 etc. Let's say this array is called $products.

What I want to ask is is there some possibility to have array which I get by using 'find' model's function ('conditions' => array('Product.id' => $products)) to be sorted not by some of Model.field values (as in 'order' option), but by $products array indices, so that when I render the order contents in view I would get all those products in cart sorted in such order as user added them.

Here's an example - Session array $products:

[0] => 35,
[1] => 15,
[2] => 25

Then I pass this array to conditions of find function:

$list = $this->Product->find('all', array('conditions' => array('Product.id' => $products)));

In the end $list gives me array which sorted by product.id. So instead of having:

[0] => Array
    (
        [Product] => Array
            (
                [id] => 35 )),
[1] => Array
        (
            [Product] => Array
                (
                    [id] => 15 )),

[2] => Array
        (
            [Product] => Array
                (
                    [id] => 25 ))

I get:

[0] => Array
    (
        [Product] => Array
            (
                [id] => 15 )),
[1] => Array
        (
            [Product] => Array
                (
                    [id] => 25 )),
[2] => Array
        (
            [Product] => Array
                (
                    [id] => 35 ))

Using CakePHP 2.0 here. The title is a bit misleading, so to clear things up - I have session array which is populated with ids of products as user adds them to cart. So this array goes like [0] => 25, [1] => 70 etc. Let's say this array is called $products.

What I want to ask is is there some possibility to have array which I get by using 'find' model's function ('conditions' => array('Product.id' => $products)) to be sorted not by some of Model.field values (as in 'order' option), but by $products array indices, so that when I render the order contents in view I would get all those products in cart sorted in such order as user added them.

Using CakePHP 2.0 here. The title is a bit misleading, so to clear things up - I have session array which is populated with ids of products as user adds them to cart. So this array goes like [0] => 25, [1] => 70 etc. Let's say this array is called $products.

What I want to ask is is there some possibility to have array which I get by using 'find' model's function ('conditions' => array('Product.id' => $products)) to be sorted not by some of Model.field values (as in 'order' option), but by $products array indices, so that when I render the order contents in view I would get all those products in cart sorted in such order as user added them.

Here's an example - Session array $products:

[0] => 35,
[1] => 15,
[2] => 25

Then I pass this array to conditions of find function:

$list = $this->Product->find('all', array('conditions' => array('Product.id' => $products)));

In the end $list gives me array which sorted by product.id. So instead of having:

[0] => Array
    (
        [Product] => Array
            (
                [id] => 35 )),
[1] => Array
        (
            [Product] => Array
                (
                    [id] => 15 )),

[2] => Array
        (
            [Product] => Array
                (
                    [id] => 25 ))

I get:

[0] => Array
    (
        [Product] => Array
            (
                [id] => 15 )),
[1] => Array
        (
            [Product] => Array
                (
                    [id] => 25 )),
[2] => Array
        (
            [Product] => Array
                (
                    [id] => 35 ))
Source Link
kK-Storm
  • 492
  • 1
  • 5
  • 20
Loading