本文整理匯總了PHP中J2Store::utilities方法的典型用法代碼示例。如果您正苦於以下問題:PHP J2Store::utilities方法的具體用法?PHP J2Store::utilities怎麽用?PHP J2Store::utilities使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類J2Store
的用法示例。
在下文中一共展示了J2Store::utilities方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onBeforeSave
public function onBeforeSave(&$model, &$data)
{
$utility_helper = J2Store::utilities();
if (isset($data['cross_sells'])) {
$data['cross_sells'] = $utility_helper->to_csv($data['cross_sells']);
} else {
$data['cross_sells'] = '';
}
if (isset($data['up_sells'])) {
$data['up_sells'] = $utility_helper->to_csv($data['up_sells']);
} else {
$data['up_sells'] = '';
}
if (isset($data['shippingmethods']) && !empty($data['shippingmethods'])) {
$data['shippingmethods'] = implode(',', $data['shippingmethods']);
}
if (isset($data['item_options']) && count($data['item_options']) > 0) {
$data['has_options'] = 1;
}
//bind existing params
if ($data['j2store_product_id']) {
$product = F0FTable::getAnInstance('Product', 'J2StoreTable');
$product->load($data['j2store_product_id']);
if ($product->params) {
$product->params = json_decode($product->params);
$data['params'] = array_merge((array) $product->params, (array) $data['params']);
}
}
if (isset($data['params']) && !empty($data['params'])) {
$data['params'] = json_encode($data['params']);
}
$this->_rawData = $data;
}
示例2: read
function read()
{
// Makes sure SiteGround's SuperCache doesn't cache the subscription page
J2Store::utilities()->nocache();
$app = JFactory::getApplication();
$app->setHeader('X-Cache-Control', 'False', true);
$method = $app->input->getCmd('method', 'none');
$model = $this->getModel('Callback');
$result = $model->runCallback($method);
echo $result ? 'OK' : 'FAILED';
$app->close();
}
示例3: onBeforeSave
public function onBeforeSave(&$model, &$data)
{
$utility_helper = J2Store::utilities();
if (isset($data['cross_sells'])) {
$data['cross_sells'] = $utility_helper->to_csv($data['cross_sells']);
} else {
$data['cross_sells'] = '';
}
if (isset($data['up_sells'])) {
$data['up_sells'] = $utility_helper->to_csv($data['up_sells']);
} else {
$data['up_sells'] = '';
}
if (isset($data['shippingmethods']) && !empty($data['shippingmethods'])) {
$data['shippingmethods'] = implode(',', $data['shippingmethods']);
}
if (isset($data['item_options']) && count($data['item_options']) > 0) {
$data['has_options'] = 1;
}
$this->_rawData = $data;
}
示例4: Copyright
<?php
/*------------------------------------------------------------------------
# mod_j2store_cart - J2 Store Cart
# ------------------------------------------------------------------------
# author Sasi varna kumar - Weblogicx India http://www.weblogicxindia.com
# copyright Copyright (C) 2014 - 19 Weblogicxindia.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://j2store.org
# Technical Support: Forum - http://j2store.org/forum/index.html
-------------------------------------------------------------------------*/
// no direct access
defined('_JEXEC') or die('Restricted access');
$app = JFactory::getApplication();
require_once JPATH_ADMINISTRATOR . '/components/com_j2store/helpers/j2store.php';
J2Store::utilities()->nocache();
$ajax = $app->getUserState('mod_j2store_mini_cart.isAjax');
$hide = false;
if ($params->get('check_empty', 0) && $list['product_count'] < 1) {
$hide = true;
}
?>
<?php
if (!$ajax) {
?>
<div class="j2store_cart_module_<?php
echo $module->id;
?>
">
<?php
示例5: onBeforeAddCartItem
public function onBeforeAddCartItem(&$model, $product, &$json)
{
$app = JFactory::getApplication();
$product_helper = J2Store::product();
$values = $app->input->getArray($_REQUEST);
$errors = array();
//run quantity check
$quantity = $app->input->get('product_qty');
if (isset($quantity)) {
$quantity = $quantity;
} else {
$quantity = 1;
}
//get options
//get the product options
$options = $app->input->get('product_option', array(0), 'ARRAY');
if (isset($options)) {
$options = array_filter($options);
} else {
$options = array();
}
//iterate through stored options for this product and validate
foreach ($product->product_options as $product_option) {
//check option type should not be file
if ($product_option->required && empty($options[$product_option->j2store_productoption_id])) {
$errors['error']['option'][$product_option->j2store_productoption_id] = JText::sprintf('J2STORE_ADDTOCART_PRODUCT_OPTION_REQUIRED', $product_option->option_name);
}
if (!empty($options[$product_option->j2store_productoption_id])) {
F0FModel::getTmpInstance('Options', 'J2StoreModel')->validateOptionRules($options[$product_option->j2store_productoption_id], $product_option, $errors);
}
}
$cart = $model->getCart();
if (!$errors && $cart->cart_type != 'wishlist') {
//before validating, get the total quantity of this variant in the cart
$cart_total_qty = $product_helper->getTotalCartQuantity($product->variants->j2store_variant_id);
//validate minimum / maximum quantity
$error = $product_helper->validateQuantityRestriction($product->variants, $cart_total_qty, $quantity);
if (!empty($error)) {
$errors['error']['stock'] = $error;
}
//validate inventory
if ($product_helper->check_stock_status($product->variants, $cart_total_qty + $quantity) === false) {
$errors['error']['stock'] = JText::_('J2STORE_OUT_OF_STOCK');
}
}
if (!$errors) {
//all good. Add the product to cart
// create cart object out of item properties
$item = new JObject();
$item->user_id = JFactory::getUser()->id;
$item->product_id = (int) $product->j2store_product_id;
$item->variant_id = (int) $product->variants->j2store_variant_id;
$item->product_qty = J2Store::utilities()->stock_qty($quantity);
$item->product_options = base64_encode(serialize($options));
$item->product_type = $product->product_type;
$item->vendor_id = isset($product->vendor_id) ? $product->vendor_id : '0';
// onAfterCreateItemForAddToCart: plugin can add values to the item before it is being validated /added
// once the extra field(s) have been set, they will get automatically saved
$results = J2Store::plugin()->event("AfterCreateItemForAddToCart", array($item, $values));
foreach ($results as $result) {
foreach ($result as $key => $value) {
$item->set($key, $value);
}
}
// no matter what, fire this validation plugin event for plugins that extend the checkout workflow
$results = array();
$results = J2Store::plugin()->event("BeforeAddToCart", array($item, $values, $product, $product->product_options));
foreach ($results as $result) {
if (!empty($result['error'])) {
$errors['error']['general'] = $result['error'];
}
}
// when there is some error from the plugin then the cart item should not be added
if (!$errors) {
//add item to cart
$cartTable = $model->addItem($item);
if ($cartTable === false) {
//adding to cart is failed
$errors['success'] = 0;
} else {
//adding cart is successful
$errors['success'] = 1;
$errors['cart_id'] = $cartTable->j2store_cart_id;
}
}
}
$json->result = $errors;
}
示例6: update
function update()
{
$app = JFactory::getApplication();
$post = $app->input->getArray($_POST);
$productHelper = J2Store::product();
$cart_id = $this->getCartId();
$json = array();
foreach ($post['quantities'] as $cartitem_id => $quantity) {
$cartitem = F0FModel::getTmpInstance('Cartitem', 'J2StoreModel')->getItem($cartitem_id);
//sanity check
if ($cartitem->cart_id != $cart_id) {
continue;
}
// get the difference quantity
if ($this->validate($cartitem, $quantity) === false) {
// an error occured. Return it
$json['error'] = $this->getError();
continue;
// exit from the loop
}
// validation successful. Update cart
$cartitem2 = F0FTable::getInstance('Cartitem', 'J2StoreTable');
$cartitem2->load($cartitem_id);
if (empty($quantity) || $quantity < 1) {
// the user wants to remove the item from cart. so remove it
$item = new JObject();
$item->product_id = $cartitem->product_id;
$item->variant_id = $cartitem->variant_id;
$item->product_type = $cartitem->product_type;
$item->product_options = $cartitem->product_options;
$cartitem2->delete($cartitem_id);
J2Store::plugin()->event('RemoveFromCart', array($item));
} else {
$cartitem2->product_qty = J2Store::utilities()->stock_qty($quantity);
$cartitem2->store();
}
}
J2Store::plugin()->event('AfterUpdateCart', array($cart_id, $post));
return $json;
}
示例7: validate_order_stock
/**
* Method to validate stock in an order. Called only before placing the order.
* @return boolean True if successful | False if a condition does not match
*/
public function validate_order_stock()
{
$product_helper = J2Store::product();
$utilities = J2Store::utilities();
$items = $this->getItems();
if (count($items) < 1) {
return true;
}
$quantity_in_cart = $this->get_orderitem_stock($items);
foreach ($items as $item) {
// check quantity restrictions
if ($item->cartitem->quantity_restriction && J2Store::isPro()) {
// get quantity restriction
$product_helper->getQuantityRestriction($item->cartitem);
$quantity = $quantity_in_cart[$item->variant_id];
$min = $item->cartitem->min_sale_qty;
$max = $item->cartitem->max_sale_qty;
if ($max && $max > 0) {
if ($quantity > $max) {
JFactory::getApplication()->enqueueMessage(JText::sprintf("J2STORE_CART_ITEM_MAXIMUM_QUANTITY_REACHED", $item->orderitem_name, $utilities->stock_qty($max), $utilities->stock_qty($quantity)));
return false;
}
}
if ($min && $min > 0) {
if ($quantity < $min) {
JFactory::getApplication()->enqueueMessage(JText::sprintf("J2STORE_CART_ITEM_MINIMUM_QUANTITY_REQUIRED", $item->orderitem_name, $utilities->stock_qty($min), $utilities->stock_qty($quantity)));
return false;
}
}
}
if ($product_helper->managing_stock($item->cartitem) && $product_helper->backorders_allowed($item->cartitem) == false) {
$productQuantity = F0FTable::getInstance('ProductQuantity', 'J2StoreTable')->getClone();
$productQuantity->load(array('variant_id' => $item->variant_id));
// no stock, right now?
if ($productQuantity->quantity < 1) {
JFactory::getApplication()->enqueueMessage(JText::sprintf("J2STORE_CART_ITEM_STOCK_NOT_AVAILABLE", $item->orderitem_name));
return false;
}
// not enough stock ?
if ($productQuantity->quantity > 0 && $quantity_in_cart[$item->variant_id] > $productQuantity->quantity) {
JFactory::getApplication()->enqueueMessage(JText::sprintf("J2STORE_CART_ITEM_STOCK_NOT_ENOUGH_STOCK", $item->orderitem_name, $utilities->stock_qty($productQuantity->quantity)));
return false;
}
}
}
return true;
}
示例8: update
function update()
{
//first clear cache
J2Store::utilities()->nocache();
$model = $this->getThisModel();
$model->getName();
$json = $model->updateProduct();
if ($json === false) {
$json = array();
$json['errormsg'] = implode('/n', $model->getErrors());
$json['error'] = 1;
}
echo json_encode($json);
JFactory::getApplication()->close();
}
示例9: array
<span class="required">*</span>
<div class="controls">
<?php
echo J2Html::select()->clearState()->type('genericlist')->name('country_id')->idTag('country_id')->value($this->params->get('country_id'))->setPlaceHolders(array('' => JText::_('J2STORE_SELECT_OPTION')))->hasOne('Countries')->setRelations(array('fields' => array('key' => 'j2store_country_id', 'name' => 'country_name')))->getHtml();
?>
</div>
</div>
<div class="control-group">
<?php
echo J2Html::label(JText::_('J2STORE_STORE_DEFAULT_CURRENCY'), 'config_currency', array('class' => 'control-label'));
?>
<span class="required">*</span>
<div class="controls">
<?php
$currencies = J2Store::utilities()->world_currencies();
echo J2Html::select()->clearState()->type('genericlist')->name('config_currency')->value($this->params->get('config_currency', 'USD'))->setPlaceHolders($currencies)->getHtml();
?>
</div>
</div>
<div class="control-group">
<?php
echo J2Html::label(JText::_('J2STORE_CURRENCY_SYMBOL_LABEL'), 'config_currency_symbol', array('class' => 'control-label'));
?>
<div class="controls">
<?php
echo J2Html::text('config_currency_symbol', '', array('id' => 'config_currency_symbol', 'placeholder' => '$'));
?>
</div>
</div>
示例10: formatCustomFields
function formatCustomFields($type, $data_field, &$order)
{
$address = F0FTable::getAnInstance('Address', 'J2StoreTable');
$fields = J2Store::getSelectableBase()->getFields($type, $address, 'address', '', true);
foreach ($fields as $field) {
$order[$type . '_' . JString::strtolower($field->field_namekey)] = '';
}
$registry = new JRegistry();
$registry->loadString(stripslashes($data_field), 'JSON');
$custom_fields = $registry->toObject();
$row = F0FTable::getAnInstance('Orderinfo', 'J2StoreTable');
if (isset($custom_fields) && count($custom_fields)) {
foreach ($custom_fields as $namekey => $field) {
if (!property_exists($row, $type . '_' . strtolower($namekey)) && !property_exists($row, 'user_' . $namekey) && $namekey != 'country_id' && $namekey != 'zone_id' && $namekey != 'option' && $namekey != 'task' && $namekey != 'view' && $namekey != 'email') {
if (is_object($field)) {
$string = '';
if (is_array($field->value)) {
$k = count($field->value);
$i = 1;
foreach ($field->value as $value) {
$string .= JText::_($value);
if ($i != $k) {
$string .= '|';
}
$i++;
}
} elseif (is_object($field->value)) {
//convert the object into an array
$obj_array = JArrayHelper::fromObject($field->value);
$k = count($obj_array);
$i = 1;
foreach ($obj_array as $value) {
$string .= JText::_($value);
if ($i != $k) {
$string .= '|';
}
$i++;
}
} elseif (J2Store::utilities()->isJson(stripslashes($field->value))) {
$json_values = json_decode(stripslashes($field->value));
if (is_array($json_values)) {
$k = count($json_values);
$i = 1;
foreach ($json_values as $value) {
$string .= JText::_($value);
if ($i != $k) {
$string .= '|';
}
$i++;
}
} else {
$string .= JText::_($field->value);
}
} else {
$string = JText::_($field->value);
}
if (!empty($string)) {
$order[$type . '_' . JString::strtolower($namekey)] = $string;
}
}
}
}
}
}
示例11: validateQuantityRestriction
public function validateQuantityRestriction($variant, $cart_total_qty, $addto_qty = 0)
{
$error = '';
if ($variant->quantity_restriction && J2Store::isPro()) {
$quantity_total = $cart_total_qty + $addto_qty;
$min = $variant->min_sale_qty;
$max = $variant->max_sale_qty;
if ($max && $max > 0) {
if ($quantity_total > $max) {
$error = JText::sprintf('J2STORE_MAX_QUANTITY_FOR_PRODUCT', floatval($max), J2Store::utilities()->stock_qty($cart_total_qty));
}
}
if ($min && $min > 0) {
if ($quantity_total < $min) {
$error = JText::sprintf('J2STORE_MIN_QUANTITY_FOR_PRODUCT', floatval($min));
}
}
}
return $error;
}
示例12: shippingUpdate
function shippingUpdate()
{
//first clear cache
J2Store::utilities()->nocache();
J2Store::utilities()->clear_cache();
$model = $this->getModel('Carts', 'J2StoreModel');
$app = JFactory::getApplication();
$session = JFactory::getSession();
$values = $this->input->getArray($_REQUEST);
$shipping_values = array();
$shipping_values['shipping_price'] = isset($values['shipping_price']) ? $values['shipping_price'] : 0;
$shipping_values['shipping_extra'] = isset($values['shipping_extra']) ? $values['shipping_extra'] : 0;
$shipping_values['shipping_code'] = isset($values['shipping_code']) ? $values['shipping_code'] : '';
$shipping_values['shipping_name'] = isset($values['shipping_name']) ? $values['shipping_name'] : '';
$shipping_values['shipping_tax'] = isset($values['shipping_tax']) ? $values['shipping_tax'] : 0;
$shipping_values['shipping_plugin'] = isset($values['shipping_plugin']) ? $values['shipping_plugin'] : '';
$session->set('shipping_values', $shipping_values, 'j2store');
$redirect = $model->getCartUrl();
echo json_encode(array('redirect' => $redirect));
$app->close();
}
示例13: view
public function view()
{
$product_id = $this->input->getInt('id');
if (!$product_id) {
$this->setRedirect(JRoute::_('index.php'));
return;
}
//first clear cache
J2Store::utilities()->nocache();
J2Store::utilities()->clear_cache();
$app = JFactory::getApplication();
$view = $this->getThisView();
if ($model = $this->getThisModel()) {
// Push the model into the view (as default)
$view->setModel($model, true);
}
$ns = 'com_j2store.' . $this->getName();
$params = F0FModel::getTmpInstance('Products', 'J2StoreModel')->getMergedParams();
if ($params->get('item_show_vote', 0)) {
$params->set('show_vote', 1);
}
$product_helper = J2Store::product();
//get product
$product = $product_helper->setId($product_id)->getProduct();
F0FModel::getTmpInstance('Products', 'J2StoreModel')->runMyBehaviorFlag(true)->getProduct($product);
if ($product->visibility != 1 || $product->enabled != 1) {
$this->setRedirect(JRoute::_('index.php'), JText::_('J2STORE_PRODUCT_NOT_ENABLED_CONTACT_SITE_ADMIN_FOR_MORE_DETAILS'), 'warning');
return;
}
//run plugin events
$model->executePlugins($product->source, $params, 'com_content.article.productlist');
$product->product_short_desc = $model->runPrepareEventOnDescription($product->product_short_desc, $product->product_source_id, $params, 'com_content.article.productlist');
$product->product_long_desc = $model->runPrepareEventOnDescription($product->product_long_desc, $product->product_source_id, $params, 'com_content.article.productlist');
//get filters / specs by product
$filters = F0FModel::getTmpInstance('Products', 'J2StoreModel')->getProductFilters($product->j2store_product_id);
//upsells
$up_sells = array();
if ($params->get('item_show_product_upsells', 0) && !empty($product->up_sells)) {
$up_sells = $product_helper->getUpsells($product);
}
//cross sells
$cross_sells = array();
if ($params->get('item_show_product_cross_sells', 0) && !empty($product->cross_sells)) {
$cross_sells = $product_helper->getCrossSells($product);
}
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
// Look for template files in component folders
$view->addTemplatePath(JPATH_SITE . '/components/com_j2store/templates');
$view->addTemplatePath(JPATH_SITE . '/components/com_j2store/templates/default');
// Look for overrides in template folder (J2 template structure)
$view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . 'templates');
$view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . 'templates' . DS . 'default');
// Look for overrides in template folder (Joomla! template structure)
$view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . 'default');
$view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store');
// Look for specific J2 theme files
if ($params->get('subtemplate')) {
$view->addTemplatePath(JPATH_COMPONENT . DS . 'templates' . DS . $params->get('subtemplate'));
$view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . 'templates' . DS . $params->get('subtemplate'));
$view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . $params->get('subtemplate'));
}
//set up document
// Check for layout override only if this is not the active menu item
// If it is the active menu item, then the view and category id will match
$active = $app->getMenu()->getActive();
$menus = $app->getMenu();
$pathway = $app->getPathway();
$document = JFactory::getDocument();
// Because the application sets a default page title,
// we need to get it from the menu item itself
$menu = $menus->getActive();
$params->def('page_heading', $product->product_name);
$params->set('page_title', $product->product_name);
$title = $params->get('page_title', '');
// Check for empty title and add site name if param is set
if (empty($title)) {
$title = $app->get('sitename');
} elseif ($app->get('sitename_pagetitles', 0) == 1) {
$title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $title);
} elseif ($app->get('sitename_pagetitles', 0) == 2) {
$title = JText::sprintf('JPAGETITLE', $title, $app->get('sitename'));
}
$document->setTitle($title);
if ($product->source->metadesc) {
$document->setDescription($product->source->metadesc);
} else {
$metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $product->source->introtext . ' ' . $product->source->fulltext);
$metaDescItem = strip_tags($metaDescItem);
$metaDescItem = J2Store::utilities()->characterLimit($metaDescItem, 150);
$document->setDescription(html_entity_decode($metaDescItem));
}
if ($product->source->metakey) {
$document->setMetadata('keywords', $product->source->metakey);
} else {
$keywords = $params->get('menu-meta_keywords');
$document->setMetaData('keywords', $keywords);
}
$metadata = json_decode($product->source->metadata);
//.........這裏部分代碼省略.........
示例14: setItems
public function setItems($cartitems)
{
$product_helper = J2Store::product();
$productitems = array();
foreach ($cartitems as $cartitem) {
if ($cartitem->product_qty == 0) {
F0FModel::getTmpInstance('Cartitems', 'J2StoreModel')->setIds(array($cartitem->j2store_cartitem_id))->delete();
continue;
}
if ($product_helper->managing_stock($cartitem) && $product_helper->backorders_allowed($cartitem) === false) {
//this could be wrong. we are not checking the total quantity for product types other than variant type
/* if ($cartitem->product_qty > $cartitem->available_quantity && $cartitem->available_quantity >= 1) {
JFactory::getApplication ()->enqueueMessage ( JText::sprintf ( "J2STORE_CART_QUANTITY_ADJUSTED", $cartitem->product_name, $cartitem->product_qty, $cartitem->available_quantity ) );
$cartitem->product_qty = $cartitem->available_quantity;
} */
// removing the product from the cart if it's not available
if ($cartitem->available_quantity == 0) {
F0FModel::getTmpInstance('Cartitems', 'J2StoreModel')->setIds(array($cartitem->j2store_cartitem_id))->delete();
continue;
}
}
unset($orderItem);
// TODO Push this into the orders object->addItem() method?
$orderItem = $this->getTable()->getClone();
$orderItem->cart_id = $cartitem->cart_id;
$orderItem->cartitem_id = $cartitem->j2store_cartitem_id;
$orderItem->product_id = $cartitem->product_id;
$orderItem->product_source = $cartitem->product_source;
$orderItem->product_source_id = $cartitem->product_source_id;
$orderItem->product_type = $cartitem->product_type;
$orderItem->product_params = $cartitem->product_params;
$orderItem->variant_id = $cartitem->variant_id;
$orderItem->orderitem_sku = $cartitem->sku;
$orderItem->vendor_id = $cartitem->vendor_id;
$orderItem->orderitem_name = $cartitem->product_name;
$orderItem->orderitem_quantity = J2Store::utilities()->stock_qty($cartitem->product_qty);
//set the entire cartitem. We can use it later
$orderItem->cartitem = $cartitem;
// price which is not processed
$orderItem->orderitem_price = $cartitem->pricing->price;
$orderItem->orderitem_baseprice = $cartitem->pricing->base_price;
$orderItem->orderitem_option_price = $cartitem->option_price;
// the following four includes the option prices as well
// $orderItem->orderitem_price_with_tax = $cartitem->pricing->price_with_tax;
// $orderItem->orderitem_price_without_tax = $cartitem->pricing->price_without_tax;
// $orderItem->orderitem_baseprice_with_tax = $cartitem->pricing->base_price_with_tax;
// $orderItem->orderitem_baseprice_without_tax = $cartitem->pricing->base_price_without_tax;
$orderItem->orderitem_taxprofile_id = $cartitem->taxprofile_id;
$orderItem->orderitem_weight = $cartitem->weight;
$orderItem->orderitem_weight_total = $cartitem->weight_total;
//just a placeholder and also used as reference for product options
$orderItem->orderitem_attributes = $cartitem->product_options;
$orderItem->orderitem_raw_attributes = $cartitem->product_options;
//prepare options
$this->getOrderItemOptions($orderItem, $cartitem);
//prepare orderitem_params and add some data that might be useful
$this->getOrderItemParams($orderItem, $cartitem);
JPluginHelper::importPlugin('j2store');
$results = JFactory::getApplication()->triggerEvent("onJ2StoreAfterAddCartItemToOrder", array($cartitem));
foreach ($results as $result) {
foreach ($result as $key => $value) {
$orderItem->set($key, $value);
}
}
J2Store::plugin()->event('AfterAddOrderItem', array(&$orderItem));
// TODO When do attributes for selected item get set during admin-side order creation?
array_push($this->_items, $orderItem);
}
return $this;
}
示例15: onDisplay
protected function onDisplay($tpl = null)
{
$app = JFactory::getApplication();
$session = JFactory::getSession();
$view = $this->input->getCmd('view', 'cpanel');
$params = J2Store::config();
J2Store::utilities()->nocache();
$this->currency = J2Store::currency();
$this->store = J2Store::storeProfile();
if (in_array($view, array('cpanel', 'cpanels'))) {
return;
}
$country_id = $this->input->getInt('country_id');
if (isset($country_id)) {
$session->set('billing_country_id', $country_id, 'j2store');
$session->set('shipping_country_id', $country_id, 'j2store');
} elseif ($session->has('shipping_country_id', 'j2store')) {
$country_id = $session->get('shipping_country_id', '', 'j2store');
} else {
$country_id = $this->store->get('country_id');
}
$zone_id = $this->input->getInt('zone_id');
if (isset($zone_id)) {
$session->set('billing_zone_id', $zone_id, 'j2store');
$session->set('shipping_zone_id', $zone_id, 'j2store');
} elseif ($session->has('shipping_zone_id', 'j2store')) {
$zone_id = $session->get('shipping_zone_id', '', 'j2store');
} else {
$zone_id = $this->store->get('zone_id');
}
$postcode = $this->input->getString('postcode');
if (isset($postcode)) {
$session->set('shipping_postcode', $postcode, 'j2store');
} elseif ($session->has('shipping_postcode', 'j2store')) {
$postcode = $session->get('shipping_postcode', '', 'j2store');
} else {
$postcode = $this->store->get('zip');
}
$this->country_id = $country_id;
$this->zone_id = $zone_id;
$this->postcode = $postcode;
if ($params->get('hide_shipping_untill_address_selection', 1) == 0) {
$session->set('billing_country_id', $country_id, 'j2store');
$session->set('shipping_country_id', $country_id, 'j2store');
$session->set('billing_zone_id', $zone_id, 'j2store');
$session->set('shipping_zone_id', $zone_id, 'j2store');
$session->set('shipping_postcode', $postcode, 'j2store');
$session->set('force_calculate_shipping', 1, 'j2store');
}
// Load the model
$model = $this->getModel();
$items = $model->getItems();
//plugin trigger
$this->before_display_cart = '';
$before_results = J2Store::plugin()->event('BeforeDisplayCart', array($items));
foreach ($before_results as $result) {
$this->before_display_cart .= $result;
}
//trigger plugin events
$i = 0;
$onDisplayCartItem = array();
foreach ($items as $item) {
ob_start();
J2Store::plugin()->event('DisplayCartItem', array($i, $item));
$cartItemContents = ob_get_contents();
ob_end_clean();
if (!empty($cartItemContents)) {
$onDisplayCartItem[$i] = $cartItemContents;
}
$i++;
}
$this->onDisplayCartItem = $onDisplayCartItem;
$order = F0FModel::getTmpInstance('Orders', 'J2StoreModel')->populateOrder($items)->getOrder();
$order->validate_order_stock();
$this->order = $order;
$this->items = $order->getItems();
foreach ($this->items as $item) {
if (isset($item->orderitemattributes) && count($item->orderitemattributes)) {
foreach ($item->orderitemattributes as &$attribute) {
if ($attribute->orderitemattribute_type == 'file') {
unset($table);
$table = F0FTable::getInstance('Upload', 'J2StoreTable');
if ($table->load(array('mangled_name' => $attribute->orderitemattribute_value))) {
$attribute->orderitemattribute_value = $table->original_name;
}
}
}
}
}
$this->taxes = $order->getOrderTaxrates();
$this->shipping = $order->getOrderShippingRate();
$this->coupons = $order->getOrderCoupons();
$this->vouchers = $order->getOrderVouchers();
$this->taxModel = F0FModel::getTmpInstance('TaxProfiles', 'J2StoreModel');
//do we have shipping methods
$this->shipping_methods = $session->get('shipping_methods', array(), 'j2store');
$this->shipping_values = $session->get('shipping_values', array(), 'j2store');
$this->checkout_url = $model->getCheckoutUrl();
$this->continue_shopping_url = $model->getContinueShoppingUrl();
$this->after_display_cart = '';
//.........這裏部分代碼省略.........