本文整理匯總了PHP中CI::ProductOptions方法的典型用法代碼示例。如果您正苦於以下問題:PHP CI::ProductOptions方法的具體用法?PHP CI::ProductOptions怎麽用?PHP CI::ProductOptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CI
的用法示例。
在下文中一共展示了CI::ProductOptions方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: index
public function index($slug)
{
$product = \CI::Products()->slug($slug);
if (!$product) {
throw_404();
} else {
$product->images = json_decode($product->images, true);
if ($product->images) {
$product->images = array_values($product->images);
} else {
$product->images = [];
}
//set product options
$data['options'] = \CI::ProductOptions()->getProductOptions($product->id);
$data['posted_options'] = \CI::session()->flashdata('option_values');
//get related items
$data['related'] = $product->related_products;
//create view variable
$data['page_title'] = $product->name;
$data['meta'] = $product->meta;
$data['seo_title'] = !empty($product->seo_title) ? $product->seo_title : $product->name;
$data['product'] = $product;
//load the view
$this->view('product', $data);
}
}
示例2: index
public function index($slug)
{
$product = \CI::Products()->slug($slug);
//echo '<pre>'; print_r($product);exit;
if (!$product) {
throw_404();
} else {
$product->images = json_decode($product->images, true);
if ($product->images) {
$product->images = array_values($product->images);
} else {
$product->images = [];
}
// get documents
$data['documents'] = \CI::Products()->get_documents($product->id);
//echo \CI::db()->last_query(); print_r($data['documents']);exit;
//echo $product->manufacturers;exit;
// get parameter of product
$data['get_parameters_of_product'] = \CI::Products()->get_parameters_of_product($product->id, $product->primary_category, $product->manufacturers);
//echo '<pre>'; print_r($data['documents']);exit;
//set product options
$data['options'] = \CI::ProductOptions()->getProductOptions($product->id);
$data['posted_options'] = \CI::session()->flashdata('option_values');
//get related items
$data['related'] = $product->related_products;
//create view variable
$data['page_title'] = $product->name;
$data['meta'] = $product->meta;
$data['seo_title'] = !empty($product->seo_title) ? $product->seo_title : $product->name;
$data['product'] = $product;
//load the view
$this->view('product', $data);
}
}
示例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: giftCardForm
public function giftCardForm($id = false, $duplicate = false)
{
$this->product_id = $id;
\CI::load()->library('form_validation');
\CI::load()->model(array('ProductOptions', 'Categories'));
\CI::form_validation()->set_error_delimiters('<div class="error">', '</div>');
$data['categories'] = \CI::Categories()->get_categories_tiered();
$data['page_title'] = lang('giftcard_product_form');
$data['groups'] = \CI::Customers()->get_groups();
//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['track_stock'] = '';
$data['seo_title'] = '';
$data['meta'] = '';
$data['is_giftcard'] = 1;
$data['taxable'] = '';
$data['images'] = [];
$data['product_categories'] = [];
$data['product_files'] = [];
foreach ($data['groups'] as $group) {
$data['enabled_' . $group->id] = '';
}
//create the photos array for later use
$data['photos'] = [];
if ($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['quantity'] = $product->quantity;
$data['taxable'] = $product->taxable;
$data['fixed_quantity'] = $product->fixed_quantity;
$data['is_giftcard'] = $product->is_giftcard;
foreach ($data['groups'] as $group) {
$data['enabled_' . $group->id] = $product->{'enabled_' . $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 (!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');
\CI::form_validation()->set_rules('name', 'lang:name', 'trim|required|max_length[64]');
\CI::form_validation()->set_rules('slug', 'lang:slug', 'trim');
\CI::form_validation()->set_rules('description', 'lang:description', 'trim');
\CI::form_validation()->set_rules('excerpt', 'lang:excerpt', 'trim');
\CI::form_validation()->set_rules('taxable', 'lang:taxable', 'trim|numeric');
\CI::form_validation()->set_rules('fixed_quantity', 'lang:fixed_quantity', 'trim|numeric');
\CI::form_validation()->set_rules('option[giftcard_values]', 'lang:giftcard_values', 'required');
foreach ($data['groups'] as $group) {
\CI::form_validation()->set_rules('enabled_' . $group->id, lang('enabled') . '(' . $group->name . ')', 'trim|numeric');
}
/*
if we've posted already, get the photo stuff and organize it
if validation comes back negative, we feed this info back into the system
if it comes back good, then we send it with the save item
submit button has a value, so we can see when it's posted
*/
if ($duplicate) {
$data['id'] = false;
}
if (\CI::input()->post('submit')) {
//reset the product options that were submitted in the post
$data['ProductOptions'] = \CI::input()->post('option');
//.........這裏部分代碼省略.........
示例5: save
public function save($product, $options = false, $categories = false)
{
if ($product['id']) {
CI::db()->where('id', $product['id']);
CI::db()->update('products', $product);
$id = $product['id'];
} else {
CI::db()->insert('products', $product);
$id = CI::db()->insert_id();
}
//loop through the product options and add them to the db
if ($options !== false) {
// wipe the slate
CI::ProductOptions()->clearOptions($id);
// save edited values
$count = 1;
foreach ($options as $option) {
$values = $option['values'];
unset($option['values']);
$option['product_id'] = $id;
$option['sequence'] = $count;
CI::ProductOptions()->saveOption($option, $values);
$count++;
}
}
if ($categories !== false) {
if ($product['id']) {
//get all the categories that the product is in
$cats = $this->getProductCategories($id);
//generate cat_id array
$ids = [];
foreach ($cats as $c) {
$ids[] = $c->id;
}
//eliminate categories that products are no longer in
foreach ($ids as $c) {
if (!in_array($c, $categories)) {
CI::db()->delete('category_products', array('product_id' => $id, 'category_id' => $c));
}
}
//add products to new categories
foreach ($categories as $c) {
if (!in_array($c, $ids)) {
CI::db()->insert('category_products', array('product_id' => $id, 'category_id' => $c));
}
}
} else {
//new product add them all
foreach ($categories as $c) {
CI::db()->insert('category_products', array('product_id' => $id, 'category_id' => $c));
}
}
}
//return the product id
return $id;
}