Manipulate Zend_Paginator Data

736 Views Asked by At

I want to add product variations to my product view table which uses the Zend_Paginator.

With this code I get my products.

$select = $productModel->select() ... (so on)

With this code I create the paginator

$adapter = new Zend_Paginator_Adapter_DbSelect($select);
$paginator = new Zend_Paginator($adapter); 

And now I'm trying to add the product_variationsto the product data. I was trying to do this:

foreach($paginator as $key => $product) {

    // get variations   
    $variations = $productModel->getProductVariants($product['ID']);
    // overwrite $product add variations
    $product['Variations'] = $variations;
    $paginator->$key = $product;

}

But in my view controller only the product_data will be shown. The array (Variations) is missing.

How can I handle this?

TIA FRGTV10

1

There are 1 best solutions below

1
On BEST ANSWER

See this: Adding items to a paginator already created.

foreach($paginator as $key => &$product) {
    // get variations   
    $variations = $productModel->getProductVariants($product['ID']);
    // overwrite $product add variations
    $product['Variations'] = $variations;
}
unset($product);

Notice the & in foreach() - pass by reference. Then you change the referenced $product and don't need to assign anything back to $paginator.