/** * Save the current values to the database. * Appends error messages to the $Errors property. * * @param array $A Optional array of values from $_POST * @return boolean True if no errors, False otherwise */ public function Save($A = '') { global $_TABLES, $_PP_CONF; USES_paypal_class_productimage(); USES_paypal_class_ppFile(); if (is_array($A)) { $this->SetVars($A); } // Zero out the shipping amount if a non-fixed value is chosen if ($this->shipping_type < 2) { $this->shipping_amt = 0; } // Handle file uploads. This is done first so we know whether // there is a valid filename for a download product // No weight or shipping for downloads if (!empty($_FILES['uploadfile']['tmp_name'])) { $F = new ppFile('uploadfile'); $filename = $F->uploadFiles(); if ($F->areErrors() > 0) { $this->Errors[] = $F->printErrors(true); } elseif ($filename != '') { $this->file = $filename; } PAYPAL_debug('Uploaded file: ' . $this->file); } // For downloadable files, physical product options don't apply if ($this->prod_type == PP_PROD_DOWNLOAD) { $this->weight = 0; $this->shipping_type = 0; $this->shipping_amt = 0; } // Serialize the quantity discount array $qty_discounts = $this->qty_discounts; if (!is_array($qty_discounts)) { $qty_discounts = array(); } $qty_discounts = DB_escapeString(@serialize($qty_discounts)); // Insert or update the record, as appropriate if ($this->id > 0) { PAYPAL_debug('Preparing to update product id ' . $this->id); $sql1 = "UPDATE {$_TABLES['paypal.products']} SET "; $sql3 = " WHERE id='{$this->id}'"; } else { PAYPAL_debug('Preparing to save a new product.'); $sql1 = "INSERT INTO {$_TABLES['paypal.products']} SET \n dt_add = '" . DB_escapeString($_PP_CONF['now']->toMySQL()) . "',"; $sql3 = ''; } $sql2 = "name='" . DB_escapeString($this->name) . "',\n cat_id='" . (int) $this->cat_id . "',\n short_description='" . DB_escapeString($this->short_description) . "',\n description='" . DB_escapeString($this->description) . "',\n keywords='" . DB_escapeString($this->keywords) . "',\n price='" . (double) $this->price . "',\n prod_type='" . (int) $this->prod_type . "',\n weight='" . (double) $this->weight . "',\n file='" . DB_escapeString($this->file) . "',\n expiration='" . (int) $this->expiration . "',\n enabled='" . (int) $this->enabled . "',\n featured='" . (int) $this->featured . "',\n views='" . (int) $this->views . "',\n taxable='" . (int) $this->taxable . "',\n shipping_type='" . (int) $this->shipping_type . "',\n shipping_amt='" . (double) $this->shipping_amt . "',\n comments_enabled='" . (int) $this->comments_enabled . "',\n rating_enabled='" . (int) $this->rating_enabled . "',\n show_random='" . (int) $this->show_random . "',\n show_popular='" . (int) $this->show_popular . "',\n onhand='{$this->onhand}',\n track_onhand='{$this->track_onhand}',\n oversell = '{$this->oversell}',\n qty_discounts = '{$qty_discounts}',\n options='{$options}',\n custom='" . DB_escapeString($this->custom) . "',\n sale_price={$this->sale_price},\n sale_beg='" . DB_escapeString($this->sale_beg) . "',\n sale_end='" . DB_escapeString($this->sale_end) . "',\n avail_beg='" . DB_escapeString($this->avail_beg) . "',\n avail_end='" . DB_escapeString($this->avail_end) . "',\n buttons= '" . DB_escapeString($this->btn_type) . "'"; $sql = $sql1 . $sql2 . $sql3; //echo $sql;die; DB_query($sql); if (!DB_error()) { if ($this->isNew) { $this->id = DB_insertID(); } $status = true; } else { COM_errorLog("Paypal- SQL error in Product::Save: {$sql}", 1); $status = false; } PAYPAL_debug('Status of last update: ' . print_r($status, true)); if ($status) { // Handle image uploads. This is done last because we need // the product id to name the images filenames. if (!empty($_FILES['images'])) { $U = new ProductImage($this->id, 'images'); $U->uploadFiles(); if ($U->areErrors() > 0) { $this->Errors[] = $U->printErrors(false); } } // Clear the button cache self::DeleteButtons($this->id); } // Update the category crossref /*DB_delete($_TABLES['paypal.prodXcat'], 'prod_id', $prod_id); foreach ($this->categories as $cat) { DB_query("INSERT INTO {$_TABLES['paypal.prodXcat']} (prod_id, cat_id) VALUES ({$prod_id}, " . (int)$cat . ")"); }*/ if (empty($this->Errors)) { PAYPAL_debug('Update of product ' . $this->id . ' succeeded.'); return true; } else { PAYPAL_debug('Update of product ' . $this->id . ' failed.'); return false; } }