本文整理汇总了PHP中ProductDownload::save方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductDownload::save方法的具体用法?PHP ProductDownload::save怎么用?PHP ProductDownload::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductDownload
的用法示例。
在下文中一共展示了ProductDownload::save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ProductDownload
/**
* Attaches a product download asset to the price object
*
* @since 1.1
*
* @return boolean
**/
function attach_download ($id) {
if (!$id) return false;
$Download = new ProductDownload($id);
$Download->parent = $this->id;
$Download->save();
do_action('attach_product_download',$id,$this->id);
return true;
}
示例2: updateDownloadProduct
/**
* Update product download
*
* @param object $product Product
*/
public function updateDownloadProduct($product)
{
/* add or update a virtual product */
if (Tools::getValue('is_virtual_good') == 'true') {
if (!Tools::getValue('virtual_product_name')) {
$this->_errors[] = $this->l('the field') . ' <b>' . $this->l('display filename') . '</b> ' . $this->l('is required');
return false;
}
if (!Tools::getValue('virtual_product_nb_days')) {
$this->_errors[] = $this->l('the field') . ' <b>' . $this->l('number of days') . '</b> ' . $this->l('is required');
return false;
}
if (Tools::getValue('virtual_product_expiration_date') and !Validate::isDate(Tools::getValue('virtual_product_expiration_date'))) {
$this->_errors[] = $this->l('the field') . ' <b>' . $this->l('expiration date') . '</b> ' . $this->l('is not valid');
return false;
}
// The oos behavior MUST be "Deny orders" for virtual products
if (Tools::getValue('out_of_stock') != 0) {
$this->_errors[] = $this->l('The "when out of stock" behavior selection must be "deny order" for virtual products');
return false;
}
$download = new ProductDownload(Tools::getValue('virtual_product_id'));
$download->id_product = $product->id;
$download->display_filename = Tools::getValue('virtual_product_name');
$download->physically_filename = Tools::getValue('virtual_product_filename') ? Tools::getValue('virtual_product_filename') : $download->getNewFilename();
$download->date_deposit = date('Y-m-d H:i:s');
$download->date_expiration = Tools::getValue('virtual_product_expiration_date') ? Tools::getValue('virtual_product_expiration_date') . ' 23:59:59' : '';
$download->nb_days_accessible = Tools::getValue('virtual_product_nb_days');
$download->nb_downloadable = Tools::getValue('virtual_product_nb_downloable');
$download->active = 1;
if ($download->save()) {
return true;
}
} else {
/* unactive download product if checkbox not checked */
if ($id_product_download = ProductDownload::getIdFromIdProduct($product->id)) {
$productDownload = new ProductDownload($id_product_download);
$productDownload->date_expiration = date('Y-m-d H:i:s', time() - 1);
$productDownload->active = 0;
return $productDownload->save();
}
}
return false;
}
示例3: updateDownloadProduct
/**
* Update product download
*
* @param object $product Product
* @return bool
*/
public function updateDownloadProduct($product, $edit = 0)
{
$is_virtual_file = (int) Tools::getValue('is_virtual_file');
// add or update a virtual product
if (Tools::getValue('is_virtual_good') == 'true') {
$product->setDefaultAttribute(0);
//reset cache_default_attribute
if (Tools::getValue('virtual_product_expiration_date') && !Validate::isDate(Tools::getValue('virtual_product_expiration_date') && !empty($is_virtual_file))) {
if (!Tools::getValue('virtual_product_expiration_date')) {
$this->errors[] = Tools::displayError('The expiration-date attribute is required.');
return false;
}
}
// Trick's
if ($edit == 1) {
$id_product_download = (int) ProductDownload::getIdFromIdProduct((int) $product->id);
if (!$id_product_download) {
$id_product_download = (int) Tools::getValue('virtual_product_id');
}
} else {
$id_product_download = Tools::getValue('virtual_product_id');
}
$is_shareable = Tools::getValue('virtual_product_is_shareable');
$virtual_product_name = Tools::getValue('virtual_product_name');
$virtual_product_filename = Tools::getValue('virtual_product_filename');
$virtual_product_nb_days = Tools::getValue('virtual_product_nb_days');
$virtual_product_nb_downloable = Tools::getValue('virtual_product_nb_downloable');
$virtual_product_expiration_date = Tools::getValue('virtual_product_expiration_date');
if ($virtual_product_filename) {
$filename = $virtual_product_filename;
} else {
$filename = ProductDownload::getNewFilename();
}
$download = new ProductDownload((int) $id_product_download);
$download->id_product = (int) $product->id;
$download->display_filename = $virtual_product_name;
$download->filename = $filename;
$download->date_add = date('Y-m-d H:i:s');
$download->date_expiration = $virtual_product_expiration_date ? $virtual_product_expiration_date . ' 23:59:59' : '';
$download->nb_days_accessible = (int) $virtual_product_nb_days;
$download->nb_downloadable = (int) $virtual_product_nb_downloable;
$download->active = 1;
$download->is_shareable = (int) $is_shareable;
if ($download->save()) {
return true;
}
} else {
/* unactive download product if checkbox not checked */
if ($edit == 1) {
$id_product_download = (int) ProductDownload::getIdFromIdProduct((int) $product->id);
if (!$id_product_download) {
$id_product_download = (int) Tools::getValue('virtual_product_id');
}
} else {
$id_product_download = ProductDownload::getIdFromIdProduct($product->id);
}
if (!empty($id_product_download)) {
$product_download = new ProductDownload((int) $id_product_download);
$product_download->date_expiration = date('Y-m-d H:i:s', time() - 1);
$product_download->active = 0;
return $product_download->save();
}
}
return false;
}
示例4: shopp_add_product_download
/**
* shopp_add_product_download
*
* Add product download file to a product/variation.
*
* @api
* @since 1.2
*
* @param int $product id of the product the download asset will be added to
* @param string $file full or correct relative path to the download file asset.
* @param int $variant id of the variant the download asset will be attached to. For products with variants, this is a required parameter.
* @return mixed false of failure, the new download asset id on success
**/
function shopp_add_product_download($product, $file, $variant = false)
{
if (empty($product) || empty($file)) {
shopp_debug(__FUNCTION__ . ' failed: One or more missing parameters.');
return false;
}
$File = new ProductDownload();
$instore = $File->found($file);
if (!$instore && (!is_file($file) || !is_readable($file))) {
shopp_debug(__FUNCTION__ . " failed for file {$file}: File missing or unreadable.");
return false;
}
$Product = new ShoppProduct($product);
if (empty($Product->id)) {
shopp_debug(__FUNCTION__ . " failed for file {$file}: No such product with id {$product}.");
return false;
}
$Product->load_data(array('summary', 'prices'));
if ("on" == $Product->variants && false === $variant) {
shopp_debug(__FUNCTION__ . " failed for file {$file}: You must specify the variant id parameter for product {$product}.");
return false;
}
$Price = reset($Product->prices);
if (empty($Price->id)) {
shopp_debug(__FUNCTION__ . " failed for file {$file}: Failed to load product variants.");
return false;
}
if ($variant) {
$Price = false;
foreach ($Product->prices as $Price) {
if ($variant == $Price->id) {
break;
}
}
if (false === $Price) {
shopp_debug(__FUNCTION__ . " failed for file {$file}: You must specify a valid variant id parameter for product {$product}.");
return false;
}
}
// Save the uploaded file
$File->load(array('type' => 'download', 'parent' => $Price->id));
$File->parent = $Price->id;
$File->context = "price";
$File->type = "download";
$File->name = basename($file);
$File->filename = $File->name;
if (!$instore) {
$File->mime = file_mimetype($file, $File->name);
$File->size = filesize($file);
$File->store($file, 'file');
} else {
$File->uri = $file;
$File->readmeta();
}
$File->save();
if ($File->id) {
return $File->id;
}
shopp_debug(__FUNCTION__ . " failed for file {$file}");
return false;
}
示例5: downloads
/**
* AJAX behavior to process uploaded files intended as digital downloads
*
* Handles processing a file upload from a temporary file to a
* the correct storage container (DB, file system, etc)
*
* @author Jonathan Davis
* @return string JSON encoded result with DB id, filename, type & size
**/
public static function downloads()
{
$error = false;
if (isset($_FILES['Filedata']['error'])) {
$error = $_FILES['Filedata']['error'];
}
if ($error) {
die(json_encode(array('error' => Lookup::errors('uploads', $error))));
}
if (!@is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
die(json_encode(array('error' => Shopp::__('The file could not be saved because the upload was not found on the server.'))));
}
if (0 == $_FILES['Filedata']['size']) {
die(json_encode(array('error' => Shopp::__('The file could not be saved because the uploaded file is empty.'))));
}
FileAsset::mimetypes();
// Save the uploaded file
$File = new ProductDownload();
$File->parent = 0;
$File->context = "price";
$File->type = "download";
$File->name = $_FILES['Filedata']['name'];
$File->filename = $File->name;
list($extension, $mimetype, $properfile) = wp_check_filetype_and_ext($_FILES['Filedata']['tmp_name'], $File->name);
if (empty($mimetype)) {
$mimetype = 'application/octet-stream';
}
$File->mime = $mimetype;
if (!empty($properfile)) {
$File->name = $File->filename = $properfile;
}
$File->size = filesize($_FILES['Filedata']['tmp_name']);
$File->store($_FILES['Filedata']['tmp_name'], 'upload');
$Error = ShoppErrors()->code('storage_engine_save');
if (!empty($Error)) {
die(json_encode(array('error' => $Error->message(true))));
}
$File->save();
do_action('add_product_download', $File, $_FILES['Filedata']);
echo json_encode(array('id' => $File->id, 'name' => stripslashes($File->name), 'type' => $File->mime, 'size' => $File->size));
}
示例6: downloads
/**
* AJAX behavior to process uploaded files intended as digital downloads
*
* Handles processing a file upload from a temporary file to a
* the correct storage container (DB, file system, etc)
*
* @return string JSON encoded result with DB id, filename, type & size
**/
function downloads () {
$error = false;
if (isset($_FILES['Filedata']['error'])) $error = $_FILES['Filedata']['error'];
if ($error) die(json_encode(array("error" => $this->uploadErrors[$error])));
if (!is_uploaded_file($_FILES['Filedata']['tmp_name']))
die(json_encode(array("error" => __('The file could not be saved because the upload was not found on the server.','Ecart'))));
if (!is_readable($_FILES['Filedata']['tmp_name']))
die(json_encode(array("error" => __('The file could not be saved because the web server does not have permission to read the upload.','Ecart'))));
if ($_FILES['Filedata']['size'] == 0)
die(json_encode(array("error" => __('The file could not be saved because the uploaded file is empty.','Ecart'))));
// Save the uploaded file
$File = new ProductDownload();
$File->parent = 0;
$File->context = "price";
$File->type = "download";
$File->name = $_FILES['Filedata']['name'];
$File->filename = $File->name;
$File->mime = file_mimetype($_FILES['Filedata']['tmp_name'],$File->name);
$File->size = filesize($_FILES['Filedata']['tmp_name']);
$File->store($_FILES['Filedata']['tmp_name'],'upload');
$File->save();
do_action('add_product_download',$File,$_FILES['Filedata']);
echo json_encode(array("id"=>$File->id,"name"=>stripslashes($File->name),"type"=>$File->mime,"size"=>$File->size));
}