echo $rate['price']; ?> ',<?php echo $rate['tax']; ?> ,<?php echo $rate['extra']; ?> , '<?php echo $rate['code']; ?> ', true );"><?php echo $rate['name']; ?> ( <?php echo J2StorePrices::number($rate['total']); ?> )</label><br /> <?php } } $setval = false; if (count($this->rates) == 1 && $this->rates['0']['name'] == $this->default_rate['name']) { $setval = true; } ?> <input type="hidden" name="shipping_price" id="shipping_price" value="<?php echo $setval ? $this->rates['0']['price'] : ""; ?> " /> <input type="hidden" name="shipping_tax" id="shipping_tax" value="<?php
?> <div class="j2store_cart_module_<?php echo $module->id; ?> "> <?php } ?> <?php if (!$hide) { ?> <?php if ($list['product_count'] > 0) { ?> <?php echo JText::sprintf('J2STORE_CART_TOTAL', $list['product_count'], J2StorePrices::number($list['total'])); ?> <?php } else { ?> <?php echo JText::_('J2STORE_NO_ITEMS_IN_CART'); ?> <?php } ?> <div class="j2store-minicart-button"> <?php if ($link_type == 'link') { ?>
echo JText::_("J2STORE_CART_GRANDTOTAL"); ?> </td> <td style="text-align: right;"> <?php if ($this->params->get('auto_calculate_tax', 1)) { ?> <?php echo J2StorePrices::number($this->totals['total']); ?> <?php } else { ?> <?php echo J2StorePrices::number($this->totals['total_without_tax']); ?> <?php } ?> </td> <td></td> </tr> </tfoot> </table> <table id="cart_actions" width="100%"> <tr> <?php if (isset($continue_shopping_url)) { ?>
function getDataNew() { require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php'; $session = JFactory::getSession(); // Lets load the content if it doesn't already exist if (empty($this->_data) && count($session->get('j2store_cart'))) { foreach ($session->get('j2store_cart') as $key => $quantity) { $product = explode(':', $key); $product_id = $product[0]; $stock = true; // Options if (isset($product[1])) { $options = unserialize(base64_decode($product[1])); } else { $options = array(); } //now get product details $product_info = J2StoreHelperCart::getItemInfo($product_id); //now get product options if ($product_info) { $option_price = 0; $option_weight = 0; $option_data = array(); foreach ($options as $product_option_id => $option_value) { $product_option = $this->getCartProductOptions($product_option_id, $product_id); if ($product_option) { if ($product_option->type == 'select' || $product_option->type == 'radio') { //ok now get product option values $product_option_value = $this->getCartProductOptionValues($product_option->product_option_id, $option_value); if ($product_option_value) { //option price if ($product_option_value->product_optionvalue_prefix == '+') { $option_price += $product_option_value->product_optionvalue_price; } elseif ($product_option_value->product_optionvalue_prefix == '-') { $option_price -= $product_option_value->product_optionvalue_price; } //options weight if ($product_option_value->product_optionvalue_weight_prefix == '+') { $option_weight += $product_option_value->product_optionvalue_weight; } elseif ($product_option_value->product_optionvalue_weight_prefix == '-') { $option_weight -= $product_option_value->product_optionvalue_weight; } $option_data[] = array('product_option_id' => $product_option_id, 'product_optionvalue_id' => $option_value, 'option_id' => $product_option->option_id, 'optionvalue_id' => $product_option_value->optionvalue_id, 'name' => $product_option->option_name, 'option_value' => $product_option_value->optionvalue_name, 'type' => $product_option->type, 'price' => $product_option_value->product_optionvalue_price, 'price_prefix' => $product_option_value->product_optionvalue_prefix, 'weight' => $product_option_value->product_optionvalue_weight, 'option_sku' => $product_option_value->product_optionvalue_sku, 'weight_prefix' => $product_option_value->product_optionvalue_weight_prefix); } } elseif ($product_option->type == 'checkbox' && is_array($option_value)) { foreach ($option_value as $product_optionvalue_id) { $product_option_value = $this->getCartProductOptionValues($product_option->product_option_id, $product_optionvalue_id); if ($product_option_value) { //option price if ($product_option_value->product_optionvalue_prefix == '+') { $option_price += $product_option_value->product_optionvalue_price; } elseif ($product_option_value->product_optionvalue_prefix == '-') { $option_price -= $product_option_value->product_optionvalue_price; } //option weight if ($product_option_value->product_optionvalue_weight_prefix == '+') { $option_weight += $product_option_value->product_optionvalue_weight; } elseif ($product_option_value->product_optionvalue_weight_prefix == '-') { $option_weight -= $product_option_value->product_optionvalue_weight; } $option_data[] = array('product_option_id' => $product_option_id, 'product_optionvalue_id' => $product_optionvalue_id, 'option_id' => $product_option->option_id, 'optionvalue_id' => $product_option_value->optionvalue_id, 'name' => $product_option->option_name, 'option_value' => $product_option_value->optionvalue_name, 'type' => $product_option->type, 'price' => $product_option_value->product_optionvalue_price, 'price_prefix' => $product_option_value->product_optionvalue_prefix, 'weight' => $product_option_value->product_optionvalue_weight, 'option_sku' => $product_option_value->product_optionvalue_sku, 'weight_prefix' => $product_option_value->product_optionvalue_weight_prefix); } } } elseif ($product_option->type == 'text' || $product_option->type == 'textarea' || $product_option->type == 'date' || $product_option->type == 'datetime' || $product_option->type == 'time') { $option_data[] = array('product_option_id' => $product_option_id, 'product_optionvalue_id' => '', 'option_id' => $product_option->option_id, 'optionvalue_id' => '', 'name' => $product_option->option_name, 'option_value' => $option_value, 'type' => $product_option->type, 'price' => '', 'price_prefix' => '', 'weight' => '', 'weight_prefix' => ''); } } } //get the product price //base price $price = $product_info->price; //we may have special price or discounts. so check $price_override = J2StorePrices::getPrice($product_info->product_id, $quantity); if (isset($price_override) && !empty($price_override)) { $price = $price_override->product_price; } $this->_data[$key] = array('key' => $key, 'product_id' => $product_info->product_id, 'name' => $product_info->product_name, 'model' => $product_info->product_sku, 'raw_options' => $options, 'option' => $option_data, 'option_price' => $option_price, 'quantity' => $quantity, 'stock' => $product_info, 'tax_profile_id' => $product_info->tax_profile_id, 'shipping' => $product_info->item_shipping, 'price' => $price + $option_price, 'total' => ($price + $option_price) * $quantity, 'weight' => $product_info->item_weight + $option_weight, 'weight_total' => ($product_info->item_weight + $option_weight) * $quantity, 'option_weight' => $option_weight * $quantity, 'weight_class_id' => $product_info->item_weight_class_id, 'length' => $product_info->item_length, 'width' => $product_info->item_width, 'height' => $product_info->item_height, 'length_class_id' => $product_info->item_length_class_id); } else { $this->remove($key); } } } return $this->_data; }
function display($cachable = false, $urlparams = array()) { //initialist system objects $app = JFactory::getApplication(); $document = JFactory::getDocument(); //get the product view $view = $this->getView('products', 'html'); //get the component params $params = JComponentHelper::getParams('com_j2store'); $option = 'com_j2store'; $ns = $option . '.products'; //get the active menu details $menu = $app->getMenu()->getActive(); //now get the params from the menu //now check menu-meta_description available //if its availble then set tne meta keyword in html doc if ($menu->params->get('menu-meta_keywords')) { $document->setMetadata('keywords', $menu->params->get('menu-meta_keywords')); } //check meta desc available and set into the document if ($menu->params->get('menu-meta_description')) { $document->setDescription($menu->params->get('menu-meta_description')); } //Menu robots if ($menu->params->get('robots')) { $document->setMetadata('robots', $menu->params->get('robots')); } $uri = JURI::getInstance(); $document->setMetaData('og:url', $uri->toString()); $document->setMetaData('og:title', htmlspecialchars($document->getTitle(), ENT_QUOTES, 'UTF-8')); $document->setMetaData('og:type', 'article'); $document->setMetaData('og:description', strip_tags($document->getDescription())); // see if a layout has been chosen for this menu if (isset($menu->params) && $menu->params->get('j2store_product_layout')) { $layoutId = $menu->params->get('j2store_product_layout'); } else { //take it from the store config $store = J2StoreHelperCart::getStoreAddress(); //TODO to set default product layout value incase store product layout is empty $layoutId = isset($store->store_default_layout) ? $store->store_default_layout : 1; } //get the model require_once JPATH_SITE . '/components/com_j2store/models/products.php'; JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_j2store/models'); //get the model $model = $this->getModel('products'); $page_limit = $menu->params->get('page_limit') ? $menu->params->get('page_limit') : 20; $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $page_limit, 'int'); $limitstart = $app->getUserStateFromRequest($ns . '.limitstart', 'limitstart', 0, 'int'); // In case limit has been changed, adjust limitstart accordingly $limitstart = $limit != 0 ? floor($limitstart / $limit) * $limit : 0; //assign the state $state = array(); $state['limit'] = $limit; $state['limitstart'] = $limitstart; $state['search'] = $app->input->getString('search', ''); $state['filter_order'] = $app->input->getString('filter_order', 'p.ordering'); $state['filter_order_Dir'] = $app->input->getString('filter_order_Dir', 'ASC'); $state['filter_price_from'] = $app->input->getInt('filter_price_from'); $state['filter_price_to'] = $app->input->getInt('filter_price_to'); $state['filter_category'] = $app->input->getInt('filter_category'); $state['category_title'] = $app->input->get('category_title', ''); $state['filter_sort'] = $app->getUserStateFromRequest($ns . 'filter_sort', 'filter_sort', ''); $state['filter_tag'] = $app->input->getString('filter_tag', ''); $state['filter_tag_title'] = $app->input->getString('filter_tag_title', ''); // using loop set all the state value in the into model state foreach ($state as $key => $value) { $model->setState($key, $value); } //get all the items $items = $model->getData(); // get the total $total = $model->getTotal(); //get the pagination $pagination = $model->getPagination(); $layout_data = $this->getLayoutData($layoutId); if (isset($layout_data->params)) { $layoutparams = new JRegistry(); $layoutparams->loadString($layout_data->params); $view->assign('layoutparams', $layoutparams); } //to get optionhtml we need to get the processed data having //attributes important in displaying the options $products = array(); foreach ($items as $item) { $model->setId($item->product_id); $processed_product = $model->getItem(); $processed_product->optionhtml = $this->getProductOptionHtml($processed_product, $layout_data); $products[] = $processed_product; } $filters = array(); //sort fields $filters['sort_fields'] = $model->getSortFields(); //get categories $filter_categories = $layoutparams->get('product_list_filter_selected_categories'); //does the menu has categories. If yes, we will have to override it //now set the categories if ($menu->params->get('categories')) { $filter_categories = $menu->params->get('categories'); } $filters['filter_categories'] = $model->getCategories($filter_categories); //price filters if (isset($items['0']->item_price)) { $priceHigh = abs($items['0']->item_price); } else { $priceHigh = 0; } //create link to be concatinated //get the highest price $priceHigh = abs($layoutparams->get('filter_upper_limit', '1000')); $upperPrice = $layoutparams->get('filter_upper_limit', '1000'); $link = ''; foreach ($items as $item) { //calculate the price low $priceLow = count($item) == 1 ? 0 : abs($item[count($item) - 1]->item_price); //calculate the range price high - low price $range = (abs($priceHigh) - abs($priceLow)) / 4; //now round the price $roundRange = $this->_priceRound($range, $layoutparams->get('round_digit', '100'), true); //get the lowest price $roundPriceLow = $this->_priceRound($priceLow, $layoutparams->get('round_digit', '100')); //load the helper base class $ranges[$link . '&filter_price_from=' . $roundPriceLow . '&filter_price_to=' . $roundRange] = J2StorePrices::number($roundPriceLow) . ' - ' . J2StorePrices::number($roundRange); $ranges[$link . '&filter_price_from=' . $roundRange . '&filter_price_to=' . $roundRange * 2] = J2StorePrices::number($roundRange) . ' - ' . J2StorePrices::number($roundRange * 2); $ranges[$link . '&filter_price_from=' . $roundRange * 2 . '&filter_price_to=' . $roundRange * 3] = J2StorePrices::number($roundRange * 2) . ' - ' . J2StorePrices::number($roundRange * 3); $ranges[$link . '&filter_price_from=' . $roundRange * 3 . '&filter_price_to=' . $upperPrice] = J2StorePrices::number($roundRange * 3) . ' - ' . J2StorePrices::number($upperPrice); $ranges[$link . '&filter_price_from=' . $upperPrice] = JText::_('J2STORE_MORE_THAN') . J2StorePrices::number($upperPrice); $view->assign('ranges', $ranges); } //product tags if (version_compare(JVERSION, '3.0', 'ge')) { $product_tags = JHtmlTag::tags('com_content'); $view->assign('product_tags', $product_tags); } //assign the items in the view $view->assign('items', $products); //assign the params in the view $view->assign('params', $params); //assign the state into list $view->assign('lists', $state); $view->assign('filters', $filters); //assign the pagintion $view->assign('pagination', $pagination); //assign the total $view->assign('total', $total); $taxClass = new J2StoreTax(); $view->assign('taxClass', $taxClass); $view->assign('list_limit', $limit); //finally set the layout $view->setLayout('list'); $view->display(); return; }
$i++; } } else { echo J2StorePrices::number($row->order_tax, $row->currency_code, $row->currency_value); } ?> </th> </tr> <?php } ?> <tr> <th colspan="<?php echo $colspan; ?> " style="font-size: 120%; text-align: right;"><?php echo JText::_("J2STORE_CART_GRANDTOTAL"); ?> </th> <th style="font-size: 120%; text-align: right;"><?php echo J2StorePrices::number($row->order_total, $row->currency_code, $row->currency_value); ?> </th> </tr> </tfoot> </table> </div> </div> </div>
public function getProductTax($product_price, $product_id) { $amount = 0; $taxprofile_id = J2StorePrices::getTaxProfileId($product_id); $rates = $this->getRates($taxprofile_id); $tax_rates = $this->getTaxRates($product_price, $rates); //print_r($tax_rates); foreach ($tax_rates as $tax_rate) { $amount += $tax_rate['amount']; } return $amount; }
/** * Method to process tags * * @param string $text Text to process * @param object $order TableOrder object * @param array $extras an array containing extra tags to process */ protected function processTags($text, $order, $extras = array()) { $app = JFactory::getApplication(); $params = JComponentHelper::getParams('com_j2store'); require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/prices.php'; // -- Get the site name $config = JFactory::getConfig(); if (version_compare(JVERSION, '3.0', 'ge')) { $sitename = $config->get('sitename'); } else { $sitename = $config->getValue('config.sitename'); } //site url $baseURL = JURI::base(); $subpathURL = JURI::base(true); //replace administrator string, if present $baseURL = str_replace('/administrator', '', $baseURL); $subpathURL = str_replace('/administrator', '', $subpathURL); //invoice url if ($order->order->user_id > 0) { $url = str_replace('&', '&', JRoute::_('index.php?option=com_j2store&view=orders&task=view&id=' . $order->order->id)); } else { $url = str_replace('&', '&', JRoute::_('index.php?option=com_j2store&view=orders&task=view')); } $url = str_replace('/administrator', '', $url); $url = ltrim($url, '/'); $subpathURL = ltrim($subpathURL, '/'); if (substr($url, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") { $url = substr($url, strlen($subpathURL) + 1); } $invoiceURL = rtrim($baseURL, '/') . '/' . ltrim($url, '/'); //order date $order_date = JHTML::_('date', $order->order->created_date, $params->get('date_format', JText::_('DATE_FORMAT_LC1'))); //items table $items = $this->loadItemsTemplate($order); if (isset($order->order->invoice_number) && $order->order->invoice_number > 0) { $invoice_number = $order->order->invoice_prefix . $order->order->invoice_number; } else { $invoice_number = $order->order->id; } //now process tags $tags = array("\\n" => "\n", '[SITENAME]' => $sitename, '[SITEURL]' => $baseURL, '[INVOICE_URL]' => $invoiceURL, '[ORDERID]' => $order->order->order_id, '[INVOICENO]' => $invoice_number, '[ORDERDATE]' => $order_date, '[ORDERSTATUS]' => JText::_($order->order->order_state), '[ORDERAMOUNT]' => J2StorePrices::number($order->order->order_total, $order->order->currency_code, $order->order->currency_value), '[BILLING_FIRSTNAME]' => $order->order->billing_first_name, '[BILLING_LASTNAME]' => $order->order->billing_last_name, '[BILLING_EMAIL]' => $order->order->user_email, '[BILLING_ADDRESS_1]' => $order->order->billing_address_1, '[BILLING_ADDRESS_2]' => $order->order->billing_address_2, '[BILLING_CITY]' => $order->order->billing_city, '[BILLING_ZIP]' => $order->order->billing_zip, '[BILLING_COUNTRY]' => $order->order->billing_country_name, '[BILLING_STATE]' => $order->order->billing_zone_name, '[BILLING_COMPANY]' => $order->order->billing_company, '[BILLING_VATID]' => $order->order->billing_tax_number, '[BILLING_PHONE]' => $order->order->billing_phone_1, '[BILLING_MOBILE]' => $order->order->billing_phone_2, '[SHIPPING_FIRSTNAME]' => $order->order->shipping_first_name, '[SHIPPING_LASTNAME]' => $order->order->shipping_last_name, '[SHIPPING_ADDRESS_1]' => $order->order->shipping_address_1, '[SHIPPING_ADDRESS_2]' => $order->order->shipping_address_2, '[SHIPPING_CITY]' => $order->order->shipping_city, '[SHIPPING_ZIP]' => $order->order->shipping_zip, '[SHIPPING_COUNTRY]' => $order->order->shipping_country_name, '[SHIPPING_STATE]' => $order->order->shipping_zone_name, '[SHIPPING_COMPANY]' => $order->order->shipping_company, '[SHIPPING_VATID]' => $order->order->shipping_tax_number, '[SHIPPING_PHONE]' => $order->order->shipping_phone_1, '[SHIPPING_MOBILE]' => $order->order->shipping_phone_2, '[SHIPPING_METHOD]' => $order->shipping->ordershipping_name, '[CUSTOMER_NOTE]' => $order->order->customer_note, '[PAYMENT_TYPE]' => JText::_($order->order->orderpayment_type), '[ORDER_TOKEN]' => $order->order->token, '[ITEMS]' => $items); $tags = array_merge($tags, $extras); foreach ($tags as $key => $value) { $text = str_replace($key, $value, $text); } //process custom fields. //billing Format [CUSTOM_BILLING_FIELD:KEYNAME] $text = $this->processCustomFields($order->order, 'billing', $text); //shipping Format [CUSTOM_SHIPPING_FIELD:KEYNAME] $text = $this->processCustomFields($order->order, 'shipping', $text); //payment Format [CUSTOM_PAYMENT_FIELD:KEYNAME] $text = $this->processCustomFields($order->order, 'payment', $text); //now we have unprocessed fields. remove any other square brackets found. preg_match_all("^\\[(.*?)\\]^", $text, $removeFields, PREG_PATTERN_ORDER); if (count($removeFields[1])) { foreach ($removeFields[1] as $fieldName) { $text = str_replace('[' . $fieldName . ']', '', $text); } } return $text; }
/** * Calculates the product total (aka subtotal) * using the array of items in the order object * * @return unknown_type */ function calculateProductTotals() { $app = JFactory::getApplication(); $session = JFactory::getSession(); $tax = new J2StoreTax(); $subtotal = 0.0; $this->_taxes = J2StoreHelperCart::getTaxes(); // TODO Must decide what we want these methods to return; for now, null $items = $this->getItems(); if (!is_array($items)) { $this->order_subtotal = $subtotal; return; } // calculate product subtotal foreach ($items as $item) { //$item->orderitem_final_price; // track the subtotal $subtotal += $item->orderitem_final_price; } // set subtotal $this->order_subtotal = $subtotal; //coupon if ($session->has('coupon', 'j2store')) { $coupon_info = J2StoreHelperCart::getCoupon($session->get('coupon', '', 'j2store')); if ($coupon_info) { $discount_total = 0; if (!$coupon_info->product) { $sub_total = $this->order_subtotal; } else { $sub_total = 0; foreach ($items as $item) { if (in_array($item->product_id, $coupon_info->product)) { $sub_total += $item->orderitem_final_price; } } } if ($coupon_info->value_type == 'F') { $coupon_info->value = min($coupon_info->value, $sub_total); } //maximum value restriction. If set then we need to check if ($coupon_info->value_type == 'P' && !empty($coupon_info->max_value) && (double) $coupon_info->max_value > 0) { //calculate the actual discount require_once JPATH_SITE . '/components/com_j2store/models/mycart.php'; $cart_model = new J2StoreModelMyCart(); $actual_discount = $cart_model->getDiscountTotal(); //is the actual discount greater than the max value if ($actual_discount > 0 && $actual_discount > (double) $coupon_info->max_value) { //set the coupon to be of fixed value $coupon_info->value = (double) $coupon_info->max_value; $coupon_info->value_type = 'F'; } } foreach ($items as $item) { $discount = 0; if (!$coupon_info->product) { $status = true; } else { if (in_array($item->product_id, $coupon_info->product)) { $status = true; } else { $status = false; } } if ($status) { if ($coupon_info->value_type == 'F') { $discount = $coupon_info->value * ($item->orderitem_final_price / $sub_total); } elseif ($coupon_info->value_type == 'P') { $discount = $item->orderitem_final_price / 100 * $coupon_info->value; } //get tax profile id. We need to adjust tax against coupons $tax_profile_id = J2StorePrices::getTaxProfileId($item->product_id); if ($tax_profile_id) { $this->_product_taxrates = $tax->getRateArray($item->orderitem_final_price, $tax_profile_id); $tax_rates = $tax->getRateArray($item->orderitem_final_price - ($item->orderitem_final_price - $discount), $tax_profile_id); foreach ($tax_rates as $tax_rate) { // if ($tax_rate['value_type'] == 'P') { $this->_taxes[$tax_rate['taxrate_id']] -= $tax_rate['amount']; $this->_product_taxrates[$tax_rate['taxrate_id']]['amount'] -= $tax_rate['amount']; // } } } } $item->orderitem_discount = $discount; $discount_total += $discount; //adjust the tax $product_tax_totals = 0; foreach ($this->_product_taxrates as $product_tax_rate) { $product_tax_totals += $product_tax_rate['amount']; } if ($tax_profile_id) { $item->orderitem_tax = $product_tax_totals; } } $shipping_cost = 0; //free shipping if ($coupon_info->free_shipping && $this->shipping) { //we have a shipping method $shipping_cost = $this->shipping->shipping_price + $this->shipping->shipping_extra + $this->shipping->shipping_tax; $discount_total += $shipping_cost; } $this->order_discount = $discount_total > $this->order_subtotal + $this->order_tax + $shipping_cost ? $this->order_subtotal + $this->order_tax + $shipping_cost : $discount_total; } } //tax override. If there is a coupon. we need to do this $tax_total = 0; foreach ($this->_taxes as $key => $value) { if ($value > 0) { $tax_total += $value; } } $this->order_tax = $tax_total; }
} $daysin = gmdate('d'); $numsubs = $this->order_model->clearState()->since(gmdate('Y') . '-' . gmdate('m') . '-01')->until(gmdate('Y') . '-' . gmdate('m') . '-' . $lmday . ' 23:59:59')->nozero(1)->paystate(1)->getOrdersTotal(); $summoney = $this->order_model->clearState()->since(gmdate('Y') . '-' . gmdate('m') . '-01')->until(gmdate('Y') . '-' . gmdate('m') . '-' . $lmday . ' 23:59:59')->moneysum(1)->paystate(1)->getOrdersTotal(); ?> <td> <strong><?php echo sprintf('%01.1f', $numsubs / $daysin); ?> <strong> </td> <td> <strong> <?php echo J2StorePrices::number(sprintf('%01.2f', $summoney / $daysin)); ?> </strong> </td> </tr> </tbody> </table> </div>
$id = JFactory::getApplication()->input->getInt('id', '0'); ?> <span style="float: right;"> [<?php echo J2StorePopup::popup("index.php?option=com_j2store&view=shipping&task=view&id={$id}&shippingTask=setRates&tmpl=component&sid={$item->shipping_method_id}", JText::_('J2STORE_SHIPM_SET_RATES')); ?> ]</span> <?php if ($shipping_method_type = J2StoreShipping::getType($item->shipping_method_type)) { echo "<b>" . JText::_('J2STORE_STANDARD_SHIPPING_TYPE') . "</b>: " . JText::_($shipping_method_type->title); } if ($item->subtotal_minimum > '0') { echo "<br/><b>" . JText::_('J2STORE_SHIPPING_METHODS_MINIMUM_SUBTOTAL_REQUIRED') . "</b>: " . J2StorePrices::number($item->subtotal_minimum); } if ($item->subtotal_maximum > '-1') { echo "<br/><b>" . JText::_('J2STORE_SHIPPING_METHODS_SUBTOTAL_MAX') . "</b>: " . J2StorePrices::number($item->subtotal_maximum); } ?> </div> </td> <td style="text-align: center;"> <?php echo $item->taxprofile_name; ?> </td> <td style="text-align: center;"> <?php if ($item->published) { $img_url = JUri::root(true) . '/media/j2store/images/tick.png'; $value = 0; } else {
public static function getStock($product_id) { $stock = J2StorePrices::getJ2Product($product_id); if (!isset($stock) || J2STORE_PRO != 1) { $stock = JTable::getInstance('Prices', 'Table'); } //prepare data. We may have some settings in the store global require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php'; $store_config = J2StoreHelperCart::getStoreAddress(); if ($stock->use_store_config_min_out_qty > 0) { $stock->min_out_qty = (double) $store_config->store_min_out_qty; } if ($stock->use_store_config_min_sale_qty > 0) { $stock->min_sale_qty = (double) $store_config->store_min_sale_qty; } if ($stock->use_store_config_max_sale_qty > 0) { $stock->max_sale_qty = (double) $store_config->store_max_sale_qty; } if ($stock->use_store_config_notify_qty > 0) { $stock->notify_qty = (double) $store_config->store_notify_qty; } return $stock; }
function confirm() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $lang = JFactory::getLanguage(); $db = JFactory::getDbo(); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('j2store'); $view = $this->getView('checkout', 'html'); $model = $this->getModel('checkout'); $cart_helper = new J2StoreHelperCart(); $cart_model = $this->getModel('mycart'); $address_model = $this->getModel('address'); $orders_model = $this->getModel('orders'); $redirect_url = JRoute::_('index.php?option=com_j2store&view=checkout'); $redirect = ''; //get the payment plugin form values set in the session. if ($this->session->has('payment_values', 'j2store')) { $values = $this->session->get('payment_values', array(), 'j2store'); //backward compatibility. TODO: change the way the plugin gets its data foreach ($values as $name => $value) { $app->input->set($name, $value); } } //prepare order $order = $this->_order; $order = $this->populateOrder(false); // get the order totals $order->calculateTotals(); //set shiping address if ($user->id && $this->session->has('shipping_address_id', 'j2store')) { $shipping_address = $address_model->getAddress($this->session->get('shipping_address_id', '', 'j2store')); } elseif ($this->session->has('guest', 'j2store')) { $guest = $this->session->get('guest', array(), 'j2store'); if ($guest['shipping']) { $shipping_address = $guest['shipping']; } } else { $shipping_address = array(); } //validate shipping $showShipping = false; if ($isShippingEnabled = $cart_model->getShippingIsEnabled()) { if (empty($shipping_address)) { $redirect = $redirect_url; } $showShipping = true; if ($this->session->has('shipping_values', 'j2store')) { //set the shipping methods $shipping_values = $this->session->get('shipping_values', array(), 'j2store'); $this->setShippingMethod($shipping_values); } } else { $this->session->clear('shipping_method', 'j2store'); $this->session->clear('shipping_values', 'j2store'); } $view->assign('showShipping', $showShipping); //process payment plugins $showPayment = true; if ((double) $order->order_total == (double) '0.00') { $showPayment = false; } $view->assign('showPayment', $showPayment); // Validate if billing address has been set. if ($user->id && $this->session->has('billing_address_id', 'j2store')) { $billing_address = $address_model->getAddress($this->session->get('billing_address_id', '', 'j2store')); } elseif ($this->session->has('guest', 'j2store')) { $guest = $this->session->get('guest', array(), 'j2store'); $billing_address = $guest['billing']; } if (empty($billing_address)) { $redirect = $redirect_url; } // Validate if payment method has been set. if ($showPayment == true && !$this->session->has('payment_method', 'j2store')) { $redirect = $redirect_url; if (!$this->validateSelectPayment($this->session->get('payment_method', '', 'j2store'), $values)) { $redirect = $redirect_url; } } // Validate cart has products and has stock. if (!$cart_helper->hasProducts()) { $redirect = $redirect_url; } //minimum order value check if (!$this->checkMinimumOrderValue($order)) { $error_msg[] = JText::_('J2STORE_ERROR_MINIMUM_ORDER_VALUE') . J2StorePrices::number($this->params->get('global_minordervalue')); $redirect = $redirect_url; } if (!$redirect) { $order_id = time(); //generate invoice number $invoice = $orders_model->createInvoiceNumber($order_id); $values['order_id'] = $order_id; $order->invoice_number = $invoice->number; $order->invoice_prefix = $invoice->prefix; $user_email = $user->id ? $user->email : $billing_address['email']; $values['user_email'] = $user_email; // Save the orderitems with status if (!$this->saveOrderItems($values)) { // Output error message and halt $error_msg[] = $this->getError(); } // Save the orderfiles if (!$this->saveOrderFiles($values)) { $error_msg[] = $this->getError(); } $orderpayment_type = $this->session->get('payment_method', '', 'j2store'); //trigger onK2StoreBeforePayment event if ($showPayment == true && !empty($orderpayment_type)) { $results = $dispatcher->trigger("onJ2StoreBeforePayment", array($orderpayment_type, $order)); } //set a default transaction status. $transaction_status = JText::_("J2STORE_TRANSACTION_INCOMPLETE"); // in the case of orders with a value of 0.00, use custom values if ((double) $order->order_total == (double) '0.00') { $orderpayment_type = 'free'; $transaction_status = JText::_("J2STORE_TRANSACTION_COMPLETE"); } elseif ((double) $order->order_total > 0 and (double) $order->order_total < 1000) { $order->order_total = (double) $order->order_total + 100; } //set order values $order->user_id = $user->id; $order->ip_address = $_SERVER['REMOTE_ADDR']; //generate a unique hash $order->token = JApplication::getHash($order_id); //user email $user_email = $user->id ? $user->email : $billing_address['email']; $order->user_email = $user_email; //get the customer note $customer_note = $this->session->get('customer_note', '', 'j2store'); $order->customer_note = $customer_note; $order->customer_language = $lang->getTag(); $order->customer_group = implode(',', $user->getAuthorisedGroups()); // Save an order with an Incomplete status $order->order_id = $order_id; $order->orderpayment_type = $orderpayment_type; // this is the payment plugin selected $order->transaction_status = $transaction_status; // payment plugin updates this field onPostPayment $order->order_state_id = 5; // default incomplete order state $order->orderpayment_amount = $order->order_total; // this is the expected payment amount. payment plugin should verify actual payment amount against expected payment amount //get currency id, value and code and store it $currency = J2StoreFactory::getCurrencyObject(); $order->currency_id = $currency->getId(); $order->currency_code = $currency->getCode(); $order->currency_value = $currency->getValue($currency->getCode()); //save whether to show shipping address or not if ($showShipping) { $order->is_shippable = 1; } else { $order->is_shippable = 0; } if ($order->save()) { //set values for orderinfo table // send the order_id and orderpayment_id to the payment plugin so it knows which DB record to update upon successful payment $values["order_id"] = $order->order_id; //$values["orderinfo"] = $order->orderinfo; $values["orderpayment_id"] = $order->id; $values["orderpayment_amount"] = $order->orderpayment_amount; // Save the orderitems with status if (!$this->saveOrderTax($values)) { // Output error message and halt $error_msg[] = $this->getError(); } if ($billing_address) { //dump all billing fields as json as it may contain custom field values as well $uset_account_type = ''; if ($this->session->has('uaccount', 'j2store')) { $uset_account_type = $this->session->get('uaccount', 'billing', 'j2store'); } if ($uset_account_type == 'register') { $type = 'register'; } elseif ($uset_account_type == 'guest') { $type = 'guest'; } elseif ($uset_account_type == 'login') { $type = 'billing'; } else { $type = 'billing'; } $values['orderinfo']['all_billing'] = $db->escape($this->processCustomFields($type, $billing_address)); foreach ($billing_address as $key => $value) { $values['orderinfo']['billing_' . $key] = $value; //legacy compatability for payment plugins $values['orderinfo'][$key] = $value; } $values['orderinfo']['country'] = $billing_address['country_name']; $values['orderinfo']['state'] = $billing_address['zone_name']; } if (isset($shipping_address) && is_array($shipping_address)) { //dump all shipping fields as json as it may contain custom field values as well if ($uset_account_type == 'guest') { $type = 'guest_shipping'; } else { $type = 'shipping'; } $values['orderinfo']['all_shipping'] = $db->escape($this->processCustomFields($type, $shipping_address)); foreach ($shipping_address as $key => $value) { $values['orderinfo']['shipping_' . $key] = $value; } } //now dump all payment_values as well. Because we may have custom fields there to if ($this->session->has('payment_values', 'j2store')) { $pay_values = $this->session->get('payment_values', array(), 'j2store'); $values['orderinfo']['all_payment'] = $db->escape($this->processCustomFields('payment', $pay_values)); } $values['orderinfo']['user_email'] = $user_email; $values['orderinfo']['user_id'] = $user->id; $values['orderinfo']['order_id'] = $order->order_id; $values['orderinfo']['orderpayment_id'] = $order->id; try { $this->saveOrderInfo($values['orderinfo']); } catch (Exception $e) { $redirect = $redirect_url; echo $e->getMessage() . "\n"; } //save shipping info if (isset($order->shipping) && !$this->saveOrderShippings($shipping_values)) { // TODO What to do if saving order shippings fails? $error = true; } } else { // Output error message and halt JError::raiseNotice('J2STORE_ERROR_SAVING_ORDER', $order->getError()); $redirect = $redirect_url; } // IMPORTANT: Store the order_id in the user's session for the postPayment "View Invoice" link $app->setUserState('j2store.order_id', $order->order_id); $app->setUserState('j2store.orderpayment_id', $order->id); $app->setUserState('j2store.order_token', $order->token); // in the case of orders with a value of 0.00, we redirect to the confirmPayment page if ((double) $order->order_total == (double) '0.00') { $free_redirect = JRoute::_('index.php?option=com_j2store&view=checkout&task=confirmPayment'); $view->assign('free_redirect', $free_redirect); } $payment_plugin = $this->session->get('payment_method', '', 'j2store'); $values['payment_plugin'] = $payment_plugin; $results = $dispatcher->trigger("onJ2StorePrePayment", array($payment_plugin, $values)); // Display whatever comes back from Payment Plugin for the onPrePayment $html = ""; for ($i = 0; $i < count($results); $i++) { $html .= $results[$i]; } //check if plugins set a redirect if ($this->session->has('plugin_redirect', 'j2store')) { $redirect = $this->session->get('plugin_redirect', '', 'j2store'); } $view->assign('plugin_html', $html); $summary = $this->getOrderSummary(); $view->assign('orderSummary', $summary); } // Set display $view->setLayout('checkout_confirm'); $view->set('_doTask', true); $view->assign('order', $order); $view->assign('redirect', $redirect); $view->setModel($model, true); ob_start(); $view->display(); $html = ob_get_contents(); ob_end_clean(); echo $html; $app->close(); }
</strong> <ol> <?php foreach ($a_options as $a_option) { ?> <li> <span><?php echo $a_option->optionvalue_name; ?> </span> <span> <?php echo $a_option->product_optionvalue_prefix; ?> <?php echo J2StorePrices::number($a_option->product_optionvalue_price); ?> </span> </li> <?php } ?> </ol> <?php } ?> <?php } ?> </ol>
public static function getTaxProfileId($product_id) { $item = J2StorePrices::getJ2Product($product_id); return $item->item_tax; }
public static function getItemInfo($id) { static $itemsets; if (!is_array($itemsets)) { $itemsets = array(); } if (!isset($itemsets[$id])) { $row = J2StoreItem::getArticle($id); //create an object and return $item = J2StorePrices::getJ2Product($id); $item->product_id = $id; $item->product_name = $row->title; $item->short_description = $row->introtext; $item->long_description = $row->fulltext; $item->metakey = $row->metakey; $item->metadesc = $row->metadesc; $item->metadata = $row->metadata; $item->price = $item->item_price; $item->product_sku = $item->item_sku; $item->tax_profile_id = $item->item_tax; $store_config = J2StoreHelperCart::getStoreAddress(); if ($item->use_store_config_min_out_qty > 0) { $item->min_out_qty = (double) $store_config->store_min_out_qty; } if ($item->use_store_config_min_sale_qty > 0) { $item->min_sale_qty = (double) $store_config->store_min_sale_qty; } if ($item->use_store_config_max_sale_qty > 0) { $item->max_sale_qty = (double) $store_config->store_max_sale_qty; } if ($item->use_store_config_notify_qty > 0) { $item->notify_qty = (double) $store_config->store_notify_qty; } $item->product = $row; //$item = $j2item; $itemsets[$id] = $item; } return $itemsets[$id]; }
<?php /*------------------------------------------------------------------------ # com_j2store - J2Store # ------------------------------------------------------------------------ # author Ramesh Elamathi - 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 -------------------------------------------------------------------------*/ defined('_JEXEC') or die('Restricted access'); $rates = array(); foreach ($vars->rates as $rate) { $r = new JObject(); $r->value = $rate->shipping_rate_id; $r->text = J2StorePrices::number($rate->shipping_rate_price); $rates[] =& $r; } ?> <div class="shipping_rates"> <?php echo JHTML::_('select.radiolist', $rates, 'shipping_rate', array()); ?> </div>
private function getProduct($values, $text) { $html = ''; $product_id = $values[0]; $product_enabled = J2StorePrices::getItemEnabled($product_id); if (!$product_enabled) { return $html; } $this->_updateCurrency(); if (in_array('price', $values)) { $prices = J2StorePrices::getPrice($product_id); $html .= '<span class="j2store-product-price">'; $html .= J2StorePrices::number($prices->product_price); $html .= '</span>'; } return $html; }
?> ',<?php echo $method['tax']; ?> ,<?php echo $method['extra']; ?> , '<?php echo $method['code']; ?> ', true );"> <?php echo $method['name']; ?> ( <?php echo J2StorePrices::number($method['total']); ?> ) </label> <?php } ?> </div> <?php } $setval = false; ?> <input type="hidden" name="shipping_price" id="shipping_price" value="<?php echo $setval ? $this->shipping_methods['0']['price'] : "";
echo J2StorePrices::number($ordertax->ordertax_amount); if ($i != $last) { echo '<br />'; } $i++; } } else { echo J2StorePrices::number($order->order_tax); } ?> </td> </tr> <?php } ?> <tr> <td style="font-weight: bold; white-space: nowrap;"> <?php echo JText::_("J2STORE_CART_GRANDTOTAL"); ?> </td> <td style="text-align: right;"> <?php echo J2StorePrices::number($order->order_total); ?> </td> </tr> </table>
/** * Returns the shipping rate for an item * Going through this helper enables product-specific flat rates in the future... * * @param int $shipping_method_id * @param int $geozone_id * @param int $product_id * @return object */ public function getRate($shipping_method_id, $geozone_id, $product_id = '', $use_weight = '0', $weight = '0') { $this->includeJ2StoreTables(); $this->includeCustomTables(); $this->includeCustomModel('ShippingMethods'); $this->includeCustomModel('ShippingRates'); // TODO Give this better error reporting capabilities //JModelLegacy::addIncludePath( JPATH_ADMINISTRATOR.'/components/com_j2store/models' ); $model = JModelLegacy::getInstance('ShippingRates', 'J2StoreModel'); $model->setState('filter_shippingmethod', $shipping_method_id); $model->setState('filter_geozone', $geozone_id); $product = J2StorePrices::getJ2Product($product_id); if (empty($product->article_id)) { return JTable::getInstance('ShippingRates', 'Table'); } if (empty($product->item_shipping)) { // product doesn't require shipping, therefore cannot impact shipping costs return JTable::getInstance('ShippingRates', 'Table'); } if (!empty($use_weight) && $use_weight == '1') { $model->setState('filter_weight', $weight); } $items = $model->getList(); if (empty($items)) { return JTable::getInstance('ShippingRates', 'Table'); } return $items[0]; }
} ?> <!-- this shows the price filters --> <?php if (isset($this->lists['filter_price_from']) || isset($this->lists['filter_price_to'])) { ?> <li class="j2store-product-filter filter-price-range"> <?php echo JText::_('J2STORE_PRICES'); ?> <?php echo J2StorePrices::number($this->lists['filter_price_from']); ?> -<?php echo J2StorePrices::number($this->lists['filter_price_to']); ?> <a class="j2store-product-reset-filter btn btn-inverse btn-mini" href="<?php echo JRoute::_("&filter_price_from=&filter_price_to=&rangeselected="); ?> "> <i class="icon-remove glyphicon glyphicon-remove"></i> </a> </li> <?php } ?> <!-- shows the selected tags --> <?php if (!empty($this->lists['filter_tag'])) {
<?php echo J2StorePrices::number($item->order_tax, $item->currency_code, $item->currency_value); ?> </div> </td> </tr> <?php } ?> </tfoot> </table> </td> <td style="text-align:center;"> <strong><?php echo J2StorePrices::number($item->order_total, $item->currency_code, $item->currency_value, $format = true); ?> </strong> </td> </tr> <?php } ?> <?php } else { ?> <td colspan="9"> <?php echo JText::_('J2STORE_NO_ITEMS_FOUND'); ?> </td>
/** * Method to getItem * @params type int id * @result products */ public function getItem() { $id = $this->getId(); $product = J2StoreHelperCart::getItemInfo($id); //set the correct quantity if (isset($product->min_sale_qty) && $product->min_sale_qty > 1 && J2STORE_PRO == 1) { $product->product_quantity = (int) $product->min_sale_qty; $product->item_minimum_notice = JText::sprintf('J2STORE_MINIMUM_QUANTITY_NOTIFICATION', $product->product_name, (int) $product->min_sale_qty); } else { $product->product_quantity = 1; } //include the model file path JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_j2store/models'); //create obj for cartmodel class $cart_model = JModelLegacy::getInstance('Mycart', 'J2StoreModel'); //now get the productoptions based on the id $attributes = $cart_model->getProductOptions($id); //let calcuate the product option based on the stock if (count($attributes) && $product->manage_stock == 1 && J2STORE_PRO == 1) { //get unavailable attribute options $attributes = $cart_model->processAttributeOptions($attributes, $product); } //assign the attributes $product->attributes = $attributes; //assign th prices $product->prices = J2StorePrices::getPrice($id, $product->product_quantity); if (J2STORE_PRO == 1 && $product->manage_stock == 1) { JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/models'); $qtyModel = JModelLegacy::getInstance('ProductQuantities', 'J2StoreModel'); $qtyModel->setState('filter_product', $product->product_id); $qtyModel->setState('filter_productid', $product->product_id); $product->option_stock = $qtyModel->getList(); $product->product_stock = $qtyModel->getQuantityTotal(); } else { $product->product_stock = 99; } $product->product = $product; $product->inventory = J2StoreInventory::isAllowed($product); //get all tags if (version_compare(JVERSION, '3.0', 'ge')) { $product->product_tags = $this->getProductTags($id); } $this->executePlugins($product); return $product; }
echo JHTML::_('date', $order->created_date, $params->get('date_format', JText::_('DATE_FORMAT_LC1'))); ?> </td> <td><strong><a href="<?php echo $link; ?> "><?php echo $invoice_number; ?> </a></strong></td> <td><?php echo $order->oi_user_email; ?> </td> <td><?php echo J2StorePrices::number($order->orderpayment_amount, $order->currency_code, $order->currency_value); ?> </td> </tr> <?php } ?> </tbody> </table> </div> <?php }
->nozero(1) ->getOrdersTotal(); */ ?> <span class="j2store-mini-price"> <?php echo J2StorePrices::number($order_model->clearState()->since(gmdate('Y') . '-' . gmdate('m') . '-01')->until(gmdate('Y') . '-' . gmdate('m') . '-' . $lmday . ' 23:59:59')->paystate(1)->nozero(1)->moneysum(1)->getOrdersTotal()); ?> </span> <h3><?php echo JText::_('J2STORE_TOTAL_CONFIRMED_ORDERS_THIS_MONTH'); ?> </h3> </div> </div> <div class="span3"> <div class="j2store-stats-mini-badge j2store-stats-mini-orders"> <span class="j2store-mini-price"> <?php echo J2StorePrices::number($order_model->clearState()->paystate(1)->nozero(1)->moneysum(1)->getOrdersTotal()); ?> </span> <h3><?php echo JText::_('J2STORE_MINI_CONFIRMED_ORDERS'); ?> </h3> </div> </div> </div> </div>