/**
  * 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);
    }
Ejemplo n.º 3
0
 /**
  * Save changes to the bundle to the database
  *
  * @param Bundle $bundle
  */
 public function save(Bundle $bundle)
 {
     $this->_transaction->add("\n\t\t\tUPDATE\n\t\t\t\tdiscount_bundle\n\t\t\tSET\n\t\t\t\t`name` = :name?s,\n\t\t\t\tallow_codes = :allowsCodes?b,\n\t\t\t\tstart = :start?dn,\n\t\t\t\t`end` = :end?dn,\n\t\t\t\tupdated_at = :updatedAt?d,\n\t\t\t\tupdated_by = :updatedBy?i\n\t\t\tWHERE\n\t\t\t\tbundle_id = :bundleID?i\n\t\t", ['name' => $bundle->getName(), 'allowsCodes' => $bundle->allowsCodes(), 'start' => $bundle->getStart(), 'end' => $bundle->getEnd(), 'updatedAt' => new \DateTime(), 'updatedBy' => $this->_user->id, 'bundleID' => $bundle->getID()]);
     $this->_productCreate->save($bundle);
     $this->_priceCreate->setTransaction($this->_transaction);
     $this->_priceCreate->save($bundle);
     $this->_imageCreate->setTransaction($this->_transaction);
     $this->_imageCreate->save($bundle);
     $this->_commitTransaction();
 }
 /**
  * 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);
         }
     }
 }
 /**
  * Mark a bundle as not deleted
  *
  * @param Bundle $bundle
  */
 public function restore(Bundle $bundle)
 {
     $this->_query->run("\n\t\t\tUPDATE\n\t\t\t\tdiscount_bundle\n\t\t\tSET\n\t\t\t\tdeleted_at = NULL,\n\t\t\t\tdeleted_by = NULL\n\t\t\tWHERE\n\t\t\t\tbundle_id = :id?i\n\t\t", ['id' => $bundle->getID()]);
 }