本文整理汇总了PHP中ProductDownload::load方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductDownload::load方法的具体用法?PHP ProductDownload::load怎么用?PHP ProductDownload::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductDownload
的用法示例。
在下文中一共展示了ProductDownload::load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}