本文整理匯總了PHP中CI::DigitalProducts方法的典型用法代碼示例。如果您正苦於以下問題:PHP CI::DigitalProducts方法的具體用法?PHP CI::DigitalProducts怎麽用?PHP CI::DigitalProducts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CI
的用法示例。
在下文中一共展示了CI::DigitalProducts方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: download
public function download($fileId, $orderId)
{
//get the order.
$order = \CI::db()->where('orders.id', $orderId)->join('customers', 'customers.id = orders.customer_id')->get('orders')->row();
$file = \CI::db()->where('order_item_files.id', $fileId)->join('digital_products', 'digital_products.id = order_item_files.file_id')->get('order_item_files')->row();
if ($order && $file) {
if ($order->is_guest || $order->customer_id == $this->customer->id) {
if ($file->max_downloads == 0 || $file->downloads_used < $file->max_downloads) {
\CI::DigitalProducts()->touchDownload($fileId);
\CI::DigitalProducts()->downloadFile($file->filename);
}
} else {
//send to login page
if (\CI::Login()->isLoggedIn(false, false)) {
redirect('login');
} else {
throw_404();
}
}
} else {
//move along nothing to see here
throw_404();
}
}
示例2: download
public function download($link)
{
$filedata = \CI::DigitalProducts()->get_file_info_by_link($link);
// missing file (bad link)
if (!$filedata) {
show_404();
}
// validate download counter
if ($filedata->max_downloads > 0) {
if (intval($filedata->downloads) >= intval($filedata->max_downloads)) {
show_404();
}
}
// increment downloads counter
\CI::DigitalProducts()->touch_download($link);
// Deliver file
\CI::load()->helper('download');
force_download('uploads/digital_uploads/', $filedata->filename);
}
示例3: insertItem
public function insertItem($data = [])
{
$product = false;
$quantity = 1;
$postedOptions = false;
$downloads = false;
$combine = false;
//is this an item from a separate cart being combined?
extract($data);
if (is_int($product)) {
$product = \CI::Products()->getProduct($product);
if (!$product) {
return json_encode(['error' => lang('error_product_not_found')]);
}
//Clean up the product for the orderItems database
$product = $this->cleanProduct($product);
//get downloadable files
$downloads = \CI::DigitalProducts()->getAssociationsByProduct($product->product_id);
}
$update = false;
if (empty($product->hash)) {
$product->hash = md5(json_encode($product) . json_encode($postedOptions));
//set defaults for new items
$product->coupon_discount = 0;
$product->coupon_discount_quantity = 0;
$product->coupon_code = '';
} else {
if (!$combine) {
//this is an update
$update = true;
}
}
$product->order_id = $this->cart->id;
//loop through the products in the cart and make sure we don't have this in there already. If we do get those quantities as well
$qty_count = $quantity;
$this->getCartItems();
// refresh the cart items
foreach ($this->items as $item) {
if (intval($item->product_id) == intval($product->product_id)) {
if ($item->hash != $product->hash) {
$qty_count = $qty_count + $item->quantity;
}
}
if ($item->hash == $product->hash && !$update) {
//if the item is already in the cart, send back a message
return json_encode(['message' => lang('item_already_added')]);
}
}
if (!config_item('allow_os_purchase') && (bool) $product->track_stock) {
$stock = \CI::Products()->getProduct($product->product_id);
if ($stock->quantity < $qty_count) {
return json_encode(['error' => sprintf(lang('not_enough_stock'), $stock->name, $stock->quantity)]);
}
}
if (!$quantity || $quantity <= 0 || $product->fixed_quantity == 1) {
$product->quantity = 1;
} else {
$product->quantity = $quantity;
}
//create save options array here for use later.
$saveOptions = [];
if (!$update && $product->product_id) {
//set the base "total_price"
if ($product->saleprice > 0) {
$product->total_price = $product->saleprice;
} else {
$product->total_price = $product->price;
}
//set base "total_weight"
$product->total_weight = $product->weight;
$productOptions = \CI::ProductOptions()->getProductOptions($product->product_id);
//option error vars
$optionError = false;
$optionErrorMessage = lang('option_error') . '<br/>';
//lets validate the options
foreach ($productOptions as $productOption) {
// are we missing any required values?
$optionValue = false;
if (!empty($postedOptions[$productOption->id])) {
$optionValue = $postedOptions[$productOption->id];
}
if ((int) $productOption->required && !$optionValue) {
$optionError = true;
$optionErrorMessage .= "- " . $productOption->name . '<br/>';
continue;
// don't bother processing this particular option any further
}
//create options to save to the database in case we get past the errors
if ($productOption->type == 'checklist') {
if (is_array($optionValue)) {
foreach ($optionValue as $ov) {
foreach ($productOption->values as $productOptionValue) {
if ($productOptionValue->id == $ov) {
$saveOptions[] = ['option_name' => $productOption->name, 'value' => $productOptionValue->value, 'price' => $productOptionValue->price, 'weight' => $productOptionValue->weight];
$product->total_weight += $productOptionValue->weight;
$product->total_price += $productOptionValue->price;
}
}
}
}
//.........這裏部分代碼省略.........
示例4: form
public function form($id = false, $duplicate = false)
{
$this->product_id = $id;
\CI::load()->library('form_validation');
\CI::load()->model(array('ProductOptions', 'Categories', 'DigitalProducts', 'Customers'));
\CI::lang()->load('digital_products');
\CI::form_validation()->set_error_delimiters('<div class="error">', '</div>');
$data['groups'] = \CI::Customers()->get_groups();
$data['categories'] = \CI::Categories()->get_categories_tiered();
$data['file_list'] = \CI::DigitalProducts()->getList();
$data['page_title'] = lang('product_form');
//default values are empty if the product is new
$data['id'] = '';
$data['sku'] = '';
$data['primary_category'] = '';
$data['name'] = '';
$data['slug'] = '';
$data['description'] = '';
$data['excerpt'] = '';
$data['weight'] = '';
$data['track_stock'] = '';
$data['seo_title'] = '';
$data['meta'] = '';
$data['shippable'] = '';
$data['taxable'] = '';
$data['fixed_quantity'] = '';
$data['quantity'] = '';
$data['enabled'] = '';
$data['related_products'] = [];
$data['product_categories'] = [];
$data['images'] = [];
$data['product_files'] = [];
$data['productOptions'] = [];
foreach ($data['groups'] as $group) {
$data['enabled_' . $group->id] = '';
$data['price_' . $group->id] = '';
$data['saleprice_' . $group->id] = '';
}
//create the photos array for later use
$data['photos'] = [];
if ($id) {
// get the existing file associations and create a format we can read from the form to set the checkboxes
$pr_files = \CI::DigitalProducts()->getAssociationsByProduct($id);
foreach ($pr_files as $f) {
$data['product_files'][] = $f->file_id;
}
// get product & options data
$data['productOptions'] = \CI::ProductOptions()->getProductOptions($id);
$product = \CI::Products()->find($id, true);
//if the product does not exist, redirect them to the product list with an error
if (!$product) {
\CI::session()->set_flashdata('error', lang('error_not_found'));
redirect('admin/products');
}
//helps us with the slug generation
$this->product_name = \CI::input()->post('slug', $product->slug);
//set values to db values
$data['id'] = $id;
$data['sku'] = $product->sku;
$data['primary_category'] = $product->primary_category;
$data['name'] = $product->name;
$data['seo_title'] = $product->seo_title;
$data['meta'] = $product->meta;
$data['slug'] = $product->slug;
$data['description'] = $product->description;
$data['excerpt'] = $product->excerpt;
$data['weight'] = $product->weight;
$data['track_stock'] = $product->track_stock;
$data['shippable'] = $product->shippable;
$data['quantity'] = $product->quantity;
$data['taxable'] = $product->taxable;
$data['fixed_quantity'] = $product->fixed_quantity;
foreach ($data['groups'] as $group) {
$data['enabled_' . $group->id] = $product->{'enabled_' . $group->id};
$data['price_' . $group->id] = $product->{'price_' . $group->id};
$data['saleprice_' . $group->id] = $product->{'saleprice_' . $group->id};
}
//make sure we haven't submitted the form yet before we pull in the images/related products from the database
if (!\CI::input()->post('submit')) {
$data['product_categories'] = [];
foreach ($product->categories as $product_category) {
$data['product_categories'][] = $product_category->id;
}
$data['related_products'] = $product->related_products;
$data['images'] = (array) json_decode($product->images);
}
}
//if $data['related_products'] is not an array, make it one.
if (!is_array($data['related_products'])) {
$data['related_products'] = [];
}
if (!is_array($data['product_categories'])) {
$data['product_categories'] = [];
}
//no error checking on these
\CI::form_validation()->set_rules('caption', 'Caption');
\CI::form_validation()->set_rules('primary_photo', 'Primary');
\CI::form_validation()->set_rules('sku', 'lang:sku', 'trim');
\CI::form_validation()->set_rules('seo_title', 'lang:seo_title', 'trim');
\CI::form_validation()->set_rules('meta', 'lang:meta_data', 'trim');
//.........這裏部分代碼省略.........
示例5: form
public function form($id = false, $duplicate = false)
{
$this->product_id = $id;
\CI::load()->library('form_validation');
\CI::load()->model(array('ProductOptions', 'Categories', 'DigitalProducts', 'Customers'));
\CI::lang()->load('digital_products');
\CI::form_validation()->set_error_delimiters('<div class="error">', '</div>');
$data['groups'] = \CI::Customers()->get_groups();
$data['categories'] = \CI::Categories()->get_categories_tiered();
$data['file_list'] = \CI::DigitalProducts()->getList();
$data['page_title'] = lang('product_form');
//default values are empty if the product is new
$data['id'] = '';
$data['sku'] = '';
$data['primary_category'] = '';
$data['name'] = '';
$data['slug'] = '';
$data['description'] = '';
$data['excerpt'] = '';
$data['weight'] = '';
$data['track_stock'] = '';
$data['seo_title'] = '';
$data['meta'] = '';
$data['shippable'] = '';
$data['taxable'] = '';
$data['fixed_quantity'] = '';
$data['quantity'] = '';
$data['enabled'] = '';
$data['related_products'] = [];
$data['product_categories'] = [];
$data['images'] = [];
$data['product_files'] = [];
$data['productOptions'] = [];
foreach ($data['groups'] as $group) {
$data['enabled_' . $group->id] = '';
$data['price_' . $group->id] = '';
$data['saleprice_' . $group->id] = '';
}
// get_manufacturers
$data['manufacturers'] = \CI::Products()->get_manufacturers(true);
//create the photos array for later use
$data['photos'] = [];
if ($id) {
// get the existing file associations and create a format we can read from the form to set the checkboxes
$pr_files = \CI::DigitalProducts()->getAssociationsByProduct($id);
foreach ($pr_files as $f) {
$data['product_files'][] = $f->file_id;
}
// get product & options data
$data['productOptions'] = \CI::ProductOptions()->getProductOptions($id);
$product = \CI::Products()->find($id, true);
//if the product does not exist, redirect them to the product list with an error
if (!$product) {
\CI::session()->set_flashdata('error', lang('error_not_found'));
redirect('admin/products');
}
//helps us with the slug generation
$this->product_name = \CI::input()->post('slug', $product->slug);
//set values to db values
$data['id'] = $id;
$data['sku'] = $product->sku;
$data['primary_category'] = $product->primary_category;
$data['name'] = $product->name;
$data['seo_title'] = $product->seo_title;
$data['meta'] = $product->meta;
$data['slug'] = $product->slug;
$data['description'] = $product->description;
$data['excerpt'] = $product->excerpt;
$data['weight'] = $product->weight;
$data['dimensions'] = $product->dimensions;
$data['days'] = $product->days;
$data['ogirin'] = $product->ogirin;
$data['track_stock'] = $product->track_stock;
$data['shippable'] = $product->shippable;
$data['quantity'] = $product->quantity;
$data['taxable'] = $product->taxable;
$data['fixed_quantity'] = $product->fixed_quantity;
$data['manufacturer'] = $product->manufacturers;
$data['protection_class'] = $product->protection_class;
$data['document_link'] = $product->document_link;
foreach ($data['groups'] as $group) {
$data['enabled_' . $group->id] = $product->{'enabled_' . $group->id};
$data['price_' . $group->id] = $product->{'price_' . $group->id};
$data['saleprice_' . $group->id] = $product->{'saleprice_' . $group->id};
}
//make sure we haven't submitted the form yet before we pull in the images/related products from the database
if (!\CI::input()->post('submit')) {
$data['product_categories'] = [];
foreach ($product->categories as $product_category) {
$data['product_categories'][] = $product_category->id;
}
$data['related_products'] = $product->related_products;
$data['images'] = (array) json_decode($product->images);
}
// get document file
$data['documents'] = \CI::Products()->get_documents($id);
if ($data['primary_category'] == 1) {
// engine
$engine = \CI::Products()->find_engine($id);
$data['prime'] = isset($engine->prime) ? $engine->prime : '';
//.........這裏部分代碼省略.........
示例6: delete
public function delete($id)
{
\CI::DigitalProducts()->delete($id);
\CI::session()->set_flashdata('message', lang('message_deleted_file'));
redirect('admin/digital_products');
}