function confirm() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $lang = JFactory::getLanguage(); $db = JFactory::getDbo(); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('k2store'); $view = $this->getView('checkout', 'html'); $model = $this->getModel('checkout'); $cart_helper = new K2StoreHelperCart(); $cart_model = $this->getModel('mycart'); $orders_model = $this->getModel('orders'); $address_model = $this->getModel('address'); $redirect_url = JRoute::_('index.php?option=com_k2store&view=checkout'); $redirect = ''; //get the payment plugin form values set in the session. if ($this->session->has('payment_values', 'k2store')) { $values = $this->session->get('payment_values', array(), 'k2store'); //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', 'k2store')) { $shipping_address = $address_model->getAddress($this->session->get('shipping_address_id', '', 'k2store')); } elseif ($this->session->has('guest', 'k2store')) { $guest = $this->session->get('guest', array(), 'k2store'); 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', 'k2store')) { //set the shipping methods $shipping_values = $this->session->get('shipping_values', array(), 'k2store'); $this->setShippingMethod($shipping_values); } } else { $this->session->clear('shipping_method', 'k2store'); $this->session->clear('shipping_methods', 'k2store'); $this->session->clear('shipping_values', 'k2store'); } $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', 'k2store')) { $billing_address = $address_model->getAddress($this->session->get('billing_address_id', '', 'k2store')); } elseif ($this->session->has('guest', 'k2store')) { $guest = $this->session->get('guest', array(), 'k2store'); $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', 'k2store')) { $redirect = $redirect_url; if (!$this->validateSelectPayment($this->session->get('payment_method', '', 'k2store'), $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::_('K2STORE_ERROR_MINIMUM_ORDER_VALUE') . K2StorePrices::number($this->params->get('global_minordervalue')); $redirect = $redirect_url; } if (!$redirect) { $order_id = time(); $values['order_id'] = $order_id; //all is well so far. If this is a guest checkout, store the billing and shipping values of the guest in the address table. if ($this->session->has('guest', 'k2store')) { $guest = $this->session->get('guest', array(), 'k2store'); if (isset($guest['billing']) && count($guest['billing'])) { $address_model->addAddress('billing', $guest['billing']); } if (isset($guest['shipping']) && count($guest['shipping'])) { $address_model->addAddress('shipping', $guest['shipping']); } } // Save the orderitems with status if (!$this->saveOrderItems($values)) { // Output error message and halt $error_msg[] = $this->getError(); } $orderpayment_type = $this->session->get('payment_method', '', 'k2store'); //trigger onK2StoreBeforePayment event if ($showPayment == true && !empty($orderpayment_type)) { $results = $dispatcher->trigger("onK2StoreBeforePayment", array($orderpayment_type, $order)); } //set a default transaction status. $transaction_status = JText::_("K2STORE_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::_("K2STORE_TRANSACTION_COMPLETE"); } //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; //generate invoice number $invoice = $orders_model->createInvoiceNumber($order_id); $order->invoice_number = $invoice->number; $order->invoice_prefix = $invoice->prefix; //get the customer note $customer_note = $this->session->get('customer_note', '', 'k2store'); $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 = K2StoreFactory::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', 'k2store')) { $uset_account_type = $this->session->get('uaccount', 'billing', 'k2store'); } 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', 'k2store')) { $pay_values = $this->session->get('payment_values', array(), 'k2store'); $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('K2STORE_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('k2store.order_id', $order->order_id); $app->setUserState('k2store.orderpayment_id', $order->id); $app->setUserState('k2store.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_k2store&view=checkout&task=confirmPayment'); $view->assign('free_redirect', $free_redirect); } $payment_plugin = $this->session->get('payment_method', '', 'k2store'); $values['payment_plugin'] = $payment_plugin; $results = $dispatcher->trigger("onK2StorePrePayment", 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', 'k2store')) { $redirect = $this->session->get('plugin_redirect', '', 'k2store'); } $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(); }
$id = JFactory::getApplication()->input->getInt('id', '0'); ?> <span style="float: right;"> [<?php echo K2StorePopup::popup("index.php?option=com_k2store&view=shipping&task=view&id={$id}&shippingTask=setRates&tmpl=component&sid={$item->shipping_method_id}", JText::_('K2STORE_SHIPM_SET_RATES')); ?> ]</span> <?php if ($shipping_method_type = K2StoreShipping::getType($item->shipping_method_type)) { echo "<b>" . JText::_('K2STORE_STANDARD_SHIPPING_TYPE') . "</b>: " . $shipping_method_type->title; } if ($item->subtotal_minimum > '0') { echo "<br/><b>" . JText::_('K2STORE_SHIPPING_METHODS_MINIMUM_SUBTOTAL_REQUIRED') . "</b>: " . K2StorePrices::number($item->subtotal_minimum); } if ($item->subtotal_maximum > '-1') { echo "<br/><b>" . JText::_('K2STORE_SHIPPING_METHODS_SUBTOTAL_MAX') . "</b>: " . K2StorePrices::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/k2store/images/tick.png'; $value = 0; } else {
/** * 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 K2StoreTax(); $subtotal = 0.0; $this->_taxes = K2StoreHelperCart::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', 'k2store')) { $coupon_info = K2StoreHelperCart::getCoupon($session->get('coupon', '', 'k2store')); 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); } 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 = K2StorePrices::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; } } $this->order_discount = $discount_total > $this->order_subtotal + $this->order_tax ? $this->order_subtotal + $this->order_tax : $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; }
, '<?php echo $rate['code']; ?> ', true );" <?php echo $checked; ?> /> <strong><?php echo $rate['name']; ?> </strong> <?php if (K2StorePrices::number($rate['total']) > 0) { ?> ( <?php echo K2StorePrices::number($rate['total']); ?> ) <?php } ?> </label> </div> <?php } ?> <?php } ?> <?php }
public static function isShippingEnabled($id) { //TODO:: depricate and move to prices library require_once JPATH_ADMINISTRATOR . '/components/com_k2store/library/prices.php'; return K2StorePrices::isShippingEnabled($id); }
} $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 K2StorePrices::number(sprintf('%01.2f', $summoney / $daysin)); ?> </strong> </td> </tr> </tbody> </table> </div>
?> ',<?php echo $method['tax']; ?> ,<?php echo $method['extra']; ?> , '<?php echo $method['code']; ?> ', true );" /> <?php echo $method['name']; ?> ( <?php echo K2StorePrices::number($method['total']); ?> ) </label> </div> <?php } ?> <?php } ?> </div> <?php }
echo JText::_("K2STORE_CART_GRANDTOTAL"); ?> </td> <td style="text-align: right;"> <?php if ($this->params->get('auto_calculate_tax', 1)) { ?> <?php echo K2StorePrices::number($this->totals['total']); ?> <?php } else { ?> <?php echo K2StorePrices::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_k2store/helpers/cart.php'; $session = JFactory::getSession(); $fabricArray = array(); // Lets load the content if it doesn't already exist if (empty($this->_data) && count($session->get('k2store_cart'))) { // var_dump($session->get('fabric_id')); foreach ($session->get('fabric_id') as $key => $quantity) { $fabric = explode(':', $key); $product_id = $fabric[0]; // Options if (isset($fabric[1])) { $fabrics_id = unserialize(base64_decode($fabric[1])); } else { $fabrics_id = array(); } $fabricArray[$product_id] = $fabrics_id; } } if (empty($this->_data) && count($session->get('k2store_cart'))) { foreach ($session->get('k2store_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 = K2StoreHelperCart::getItemInfo($product_id); $divide = 1; //now get product options if ($product_info) { $option_price = 0; $option_weight = 0; $option_data = array(); $additional = ''; 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') { if (isset($fabricArray[$product_id][$product_option->product_option_id])) { $additional = $fabricArray[$product_id][$product_option->product_option_id]; } //ok now get product option values $product_option_value = $this->getCartProductOptionValues($product_option->product_option_id, $option_value); if ($product_option_value) { //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; } elseif ($product_option_value->product_optionvalue_prefix == '/') { $option_price += $product_option_value->product_optionvalue_price / 2; } //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, 'weight_prefix' => $product_option_value->product_optionvalue_weight_prefix, 'option_sku' => $product_option_value->product_optionvalue_sku, 'manage_stock' => $product_option->manage_stock, 'short_desc' => $product_option_value->pov_short_desc, 'long_desc' => $product_option_value->pov_long_desc, 'ref' => $product_option_value->pov_ref, 'additional' => $additional); } } 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; } elseif ($product_option_value->product_optionvalue_prefix == '/') { $option_price += $product_option_value->product_optionvalue_price / 2; } //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, 'weight_prefix' => $product_option_value->product_optionvalue_weight_prefix, 'option_sku' => $product_option_value->product_optionvalue_sku, 'short_desc' => $product_option_value->pov_short_desc, 'long_desc' => $product_option_value->pov_long_desc, 'ref' => $product_option_value->pov_ref); } } } 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' => ''); } } } //get the product price //base price $price = $product_info->price; //we may have special price or discounts. so check $price_override = K2StorePrices::getPrice($product_info->product_id, $quantity); if (isset($price_override) && !empty($price_override)) { $price = $price_override->product_price; } /*poparada hack*/ if ($option_price > 0) { $total_option_price = $option_price / $divide; } else { $total_option_price = $price; } $this->_data[$key] = array('key' => $key, 'product_id' => $product_info->product_id, 'name' => $product_info->product_name, 'model' => $product_info->product_sku, 'option' => $option_data, 'option_price' => $option_price, 'quantity' => $quantity, 'stock' => $product_info->stock, 'tax_profile_id' => $product_info->tax_profile_id, 'shipping' => $product_info->item_shipping, 'price' => $total_option_price, 'total' => $total_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); } } } // var_dump($this->_data); return $this->_data; }
public function getProductTax($product_price, $product_id) { $amount = 0; $taxprofile_id = K2StorePrices::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; }
<?php defined('_JEXEC') or die('Restricted access'); $rates = array(); foreach ($vars->rates as $rate) { $r = new JObject(); $r->value = $rate->shipping_rate_id; $r->text = K2StorePrices::number($rate->shipping_rate_price); $rates[] =& $r; } ?> <div class="shipping_rates"> <?php echo JHTML::_('select.radiolist', $rates, 'shipping_rate', array()); ?> </div>
</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 K2StorePrices::number($a_option->product_optionvalue_price); ?> </span> </li> <?php } ?> </ol> <?php } ?> <?php } ?> </ol>
function add() { $app = JFactory::getApplication(); JFactory::getDocument()->setCharset('utf-8'); $params = JComponentHelper::getParams('com_k2store'); $model = $this->getModel('mycart'); $cart_helper = new K2StoreHelperCart(); require_once JPATH_COMPONENT . '/helpers/cart.php'; $error = array(); $json = array(); //get the product id $product_id = $app->input->getInt('product_id', 0); //no product id?. return an error if (empty($product_id)) { $error['error']['product'] = JText::_('K2STORE_ADDTOCART_ERROR_MISSING_PRODUCT_ID'); echo json_encode($error); $app->close(); } //Ok. we have a product id. so proceed. //get the quantity $quantity = $app->input->get('product_qty'); if (isset($quantity)) { $quantity = $quantity; } else { $quantity = 1; } $product = $cart_helper->getItemInfo($product_id); //get the product options $options = $app->input->get('product_option', array(0), 'ARRAY'); $fabrics = $app->input->get('fabric', array(0), 'ARRAY'); if (isset($options)) { $options = array_filter($options); } else { $options = array(); } $product_options = $model->getProductOptions($product_id); //iterate through stored options for this product and validate foreach ($product_options as $product_option) { if ($product_option['required'] && empty($options[$product_option['product_option_id']])) { $json['error']['option'][$product_option['product_option_id']] = JText::sprintf('K2STORE_ADDTOCART_PRODUCT_OPTION_REQUIRED', $product_option['option_name']); } } //trigger before addtocart plugin event now... send post values $post_data = $app->input->getArray($_POST); JPluginHelper::importPlugin('k2store'); $results = $app->triggerEvent("onK2StoreBeforeAddCart", array($post_data)); if (isset($results) && count($results)) { foreach ($results as $result) { if (!empty($result['error'])) { $json['warning'] = $result['error']; } } } //validation is ok. Now add the product to the cart. if (!$json) { // JFactory::getSession()->set('fabric_id', $post_data['fabric_id']); // $fabricid[$product_id] = $post_data['fabric_id']; $cart_helper->add($product_id, $quantity, $options, $fabrics); //trigger plugin event- after addtocart $app->triggerEvent("onK2StoreAfterAddCart", array($post_data)); $product_info = K2StoreHelperCart::getItemInfo($product_id); $cart_link = JRoute::_('index.php?option=com_k2store&view=mycart'); $json['success'] = true; $json['successmsg'] = $product_info->product_name . ' ' . JText::sprintf('K2STORE_ADDTOCART_ADDED_TO_CART'); $json['data'] = $post_data; //$total = K2StoreHelperCart::getTotal(); $totals = $model->getTotals(); if ($params->get('auto_calculate_tax', 1)) { $total = $totals['total']; } else { $total = $totals['total_without_tax']; } $product_count = K2StoreHelperCart::countProducts(); //get product total $json['total'] = JText::sprintf('K2STORE_CART_TOTAL', $product_count, K2StorePrices::number($total)); //get cart info //do we have to redirect to the cart if ($params->get('popup_style', 1) == 3) { $json['redirect'] = $cart_link; } } else { //do we have to redirect // $url = 'index.php?option=com_k2&view=item&id='.$product_id; // $json['redirect'] = JRoute::_($url); } echo json_encode($json); $app->close(); }
public static function getTaxProfileId($product_id) { $row = K2StorePrices::getProduct($product_id); return $row->item_tax_id; }
?> </th> <th style="text-align: right;"><?php echo K2StorePrices::number($row->order_surcharge, $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::_("K2STORE_CART_GRANDTOTAL"); ?> </th> <th style="font-size: 120%; text-align: right;"><?php echo K2StorePrices::number($row->order_total, $row->currency_code, $row->currency_value); ?> </th> </tr> </tfoot> </table> </div> </div>
?> <div class="k2store_cart_module_<?php echo $module->id; ?> "> <?php } ?> <?php if (!$hide) { ?> <?php if ($list['product_count'] > 0) { ?> <?php echo JText::sprintf('K2STORE_CART_TOTAL', $list['product_count'], K2StorePrices::number($list['total'])); ?> <?php } else { ?> <?php echo JText::_('K2STORE_NO_ITEMS_IN_CART'); ?> <?php } ?> <div class="k2store-minicart-button"> <?php if ($link_type == 'link') { ?>
} } if ($order->order_discount > 0) { echo "(-)"; echo K2StorePrices::number($order->order_discount); echo "<br />"; } if ($order->order_tax) { echo K2StorePrices::number($order->order_tax); echo "<br />"; } if ($order->order_surcharge > 0) { echo K2StorePrices::number($order->order_surcharge); } ?> </td> </tr> <tr> <td style="text-align: right; font-weight: bold; white-space: nowrap;"> <?php echo JText::_("K2STORE_CART_GRANDTOTAL"); ?> </td> <td style="text-align: right;"> <?php echo K2StorePrices::number($order->order_total); ?> </td> </tr> </tfoot> </table>
echo JHTML::_('date', $order->created_date, $this->params->get('date_format', JText::_('DATE_FORMAT_LC1'))); ?> </td> <td><strong><a href="<?php echo $link; ?> "><?php echo $order->order_id; ?> </a></strong></td> <td><?php echo $order->user_email; ?> </td> <td><?php echo K2StorePrices::number($order->orderpayment_amount, $order->currency_code, $order->currency_value); ?> </td> </tr> <?php } ?> </tbody> </table> </div> <?php }
public static function getItemInfo($id) { static $itemsets; if (!is_array($itemsets)) { $itemsets = array(); } if (!isset($itemsets[$id])) { $db = JFactory::getDBO(); $query = "SELECT * FROM #__k2_items WHERE id=" . $id; $db->setQuery($query); $row = $db->loadObject(); //get k2store variables $product = K2StorePrices::getProduct($row->id); $item = $product; $item->product_id = $row->id; $item->product_name = $row->title; // $item->price = $product->item_price; $item->product_sku = $product->item_sku; $item->tax_profile_id = $product->item_tax_id; $item->item_shipping = $product->item_shipping; $item->item_cart_text = $product->item_cart_text; //we need item metrics so load info from the products table //TODO: Why cant we load all k2store data from this table itself $item->item_minimum = isset($product->item_minimum) ? $product->item_minimum : '1'; //get the stock data and assign to it $store_config = K2StoreHelperCart::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->stock = $item; $item->product = $row; $itemsets[$id] = $item; } return $itemsets[$id]; }