/** * Load product data and create instances of ProductRow to assign to bundle * * @param BundleProxy $bundle * * @return array */ public function getProductRows(BundleProxy $bundle) { $result = $this->_queryBuilderFactory->getQueryBuilder()->select($this->_columns)->from('p', self::PRODUCT_TABLE)->leftJoin('o', 'p.product_row_id = o.product_row_id', self::OPTION_TABLE)->where('p.bundle_id = ?i', [$bundle->getID()])->orderBy('p.product_row_id ASC')->getQuery()->run(); $productRowData = []; $productRows = []; // Reorganise data into mutlidimensional array split into product rows to allow for multiple options per row foreach ($result as $row) { if (!array_key_exists($row->id, $productRowData)) { $productRowData[$row->id] = ['product_id' => $row->product_id, 'options' => $this->_getRowOptionsArray($row->option_name, $row->option_value), 'quantity' => $row->quantity]; } $productRowData[$row->id]['options'] = $productRowData[$row->id]['options'] + $this->_getRowOptionsArray($row->option_name, $row->option_value); } foreach ($productRowData as $id => $data) { $productRow = new ProductRow($data['product_id'], $data['options'], $data['quantity']); $productRow->setID($id); $productRows[] = $productRow; } return $productRows; }