/** * Save the image assignment to the database * * @param Bundle $bundle The bundle the image is assigned to * @param bool $delete If set to true, existing images will be deleted from the database. Defaults to true. */ 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_image\n\t\t\t\tWHERE\n\t\t\t\t\tbundle_id = :id?i\n\t\t\t", ['id' => $bundle->getID()]); } if ($bundle->getImage()) { $this->_query->run("\n\t\t\t\tINSERT INTO\n\t\t\t\t\tdiscount_bundle_image\n\t\t\t\t\t(\n\t\t\t\t\t\tbundle_id,\n\t\t\t\t\t\tfile_id\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:fileID?i\n\t\t\t\t\t)\n\t\t\t", ['bundleID' => $bundle->getID(), 'fileID' => $bundle->getImage()->id]); } }
/** * Save bundle prices to the database. * * @param Bundle $bundle The bundle the prices are assigned to * @param bool $delete If set to true, will delete prices currently assigned to database. 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_price\n\t\t\t\tWHERE\n\t\t\t\t\tbundle_id = :bundleID?i\n\t\t\t", ['bundleID' => $bundle->getID()]); } $statements = []; foreach ($bundle->getPrices() as $currency => $price) { $statement = '( :bundleID?i, :currency?s, :price?f )'; $params = ['bundleID' => $bundle->getID(), 'currency' => $currency, 'price' => $price]; $statements[] = $this->_queryParser->parse($statement, $params); } $statements = implode(',' . PHP_EOL, $statements); $this->_query->run("\n\t\t\t\tINSERT INTO\n\t\t\t\t\tdiscount_bundle_price\n\t\t\t\t\t(\n\t\t\t\t\t\tbundle_id,\n\t\t\t\t\t\tcurrency,\n\t\t\t\t\t\tprice\n\t\t\t\t\t)\n\t\t\t\tVALUES\n\t\t\t" . $statements); }