/** * {@inheritDoc} */ public function getProductRows() { if (!parent::getProductRows()) { $productRows = $this->_loaders->get('product_row')->getProductRows($this); foreach ($productRows as $productRow) { $this->addProductRow($productRow); } } return parent::getProductRows(); }
/** * Method for returning two arrays with matching keys. * * The first array is the expected counts array - a set of key value pairs of product row IDs and their quantity * value. * * The second array is the current counts array - a list of key value pairs of product row IDs and zeros, intended * to be incremented as the items in an order are counted against a bundle. * * @param Bundle\Bundle $bundle * * @return array Returns array with the expected counts array as the first value and the current counts * array as the second value */ function getCounts(Bundle\Bundle $bundle) { $expectedCounts = []; $currentCounts = []; foreach ($bundle->getProductRows() as $row) { $expectedCounts[$row->getID()] = $row->getQuantity(); $currentCounts[$row->getID()] = 0; } return [$expectedCounts, $currentCounts]; }
/** * Save product data assigned to a bundle to the database * * @param Bundle $bundle The bundle the product rows are assigned to * @param bool $delete If set to true, existing product rows for the bundle will be deleted. True by default. */ public function save(Bundle $bundle, $delete = true) { if ($delete) { $this->_query->run("\n\t\t\t\tDELETE FROM\n\t\t\t\t\tdiscount_bundle_product_row\n\t\t\t\tWHERE\n\t\t\t\t\tbundle_id = :bundleID?i\n\t\t\t", ['bundleID' => $bundle->getID()]); $this->_query->run("\n\t\t\t\tDELETE FROM\n\t\t\t\t\tdiscount_bundle_product_option\n\t\t\t\tWHERE\n\t\t\t\t\tbundle_id = :bundleID?i\n\t\t\t", ['bundleID' => $bundle->getID()]); } foreach ($bundle->getProductRows() as $row) { $result = $this->_query->run("\n\t\t\t\tINSERT INTO\n\t\t\t\t\tdiscount_bundle_product_row\n\t\t\t\t\t(\n\t\t\t\t\t\tbundle_id,\n\t\t\t\t\t\tproduct_id,\n\t\t\t\t\t\tquantity\n\t\t\t\t\t)\n\t\t\t\tVALUES\n\t\t\t\t\t(\n\t\t\t\t\t\t:bundleID?i,\n\t\t\t\t\t\t:productID?i,\n\t\t\t\t\t\t:quantity?i\n\t\t\t\t\t)\n\t\t\t", ['bundleID' => $bundle->getID(), 'productID' => $row->getProductID(), 'quantity' => $row->getQuantity()]); $statements = []; if (count($row->getOptions()) > 0) { foreach ($row->getOptions() as $name => $value) { $statement = "\n\t\t\t\t\t(\n\t\t\t\t\t\t:rowID?i,\n\t\t\t\t\t\t:bundleID?i,\n\t\t\t\t\t\t:name?s,\n\t\t\t\t\t\t:value?s\n\t\t\t\t\t)"; $params = ['rowID' => $result->id(), 'bundleID' => $bundle->getID(), 'name' => $name, 'value' => $value]; $statements[] = $this->_queryParser->parse($statement, $params); } $statements = implode(',' . PHP_EOL, $statements); $this->_query->run("\n\t\t\t\t\tINSERT INTO\n\t\t\t\t\t\tdiscount_bundle_product_option\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tproduct_row_id,\n\t\t\t\t\t\t\tbundle_id,\n\t\t\t\t\t\t\toption_name,\n\t\t\t\t\t\t\toption_value\n\t\t\t\t\t\t)\n\t\t\t\t\tVALUES\n\t\t\t\t" . $statements); } } }
private function _getProducts(Bundle\Bundle $bundle) { $productIDs = []; $products = []; foreach ($bundle->getProductRows() as $productRow) { $productIDs[] = $productRow->getProductID(); } foreach ($this->get('product.loader')->getByID($productIDs) as $product) { $products[$product->id] = $product; } return $products; }