Example #1
0
 public static function number($amount, $currency = '', $value = '', $format = true)
 {
     if ($value == 0) {
         $value = '';
     }
     //backward compatibility
     if (is_array($currency)) {
         $currency = '';
     }
     $currencyobject = K2StoreFactory::getCurrencyObject();
     return $currencyobject->format($amount, $currency, $value, $format);
 }
Example #2
0
</span>
							<input type="text" class="input-mini" name="product[<?php 
    echo $product->id;
    ?>
][item_price]" value="<?php 
    echo $product->item_price;
    ?>
" />
						</div>
					</td>

					<td>
						<div class="input-prepend">
							<span class="add-on">
							<?php 
    $currency = K2StoreFactory::getCurrencyObject();
    echo $currency->getSymbol();
    ?>
</span>
						<input type="text" class="input-mini" name="product[<?php 
    echo $product->id;
    ?>
][special_price]" value="<?php 
    echo $product->special_price;
    ?>
" /> </td>
					</div>
					<?php 
    if ($this->params->get('enable_inventory', 0)) {
        ?>
Example #3
0
 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();
 }
Example #4
0
 public static function getSelectableFields()
 {
     if (!self::$fields) {
         require_once 'selectable/fields.php';
         self::$fields = K2StoreSelectableFields::getInstance();
     }
     return self::$fields;
 }
 function getAmount($value, $currency_code, $currency_value, $convert = false)
 {
     if (version_compare($this->_k2version, '2.6.7', 'lt')) {
         return K2StoreUtilities::number($value, array('thousands' => '', 'num_decimals' => '2', 'decimal' => '.'));
     } else {
         include_once JPATH_ADMINISTRATOR . '/components/com_k2store/library/base.php';
         $currencyObject = K2StoreFactory::getCurrencyObject();
         $amount = $currencyObject->format($value, $currency_code, $currency_value, false);
         return $amount;
     }
 }
Example #6
0
 function setcurrency()
 {
     $app = JFactory::getApplication();
     $currency = K2StoreFactory::getCurrencyObject();
     $post = $app->input->getArray($_POST);
     if (isset($post['currency_code'])) {
         $currency->set($post['currency_code']);
     }
     //get the redirect
     if (isset($post['redirect'])) {
         $url = base64_decode($post['redirect']);
     } else {
         $url = 'index.php';
     }
     $app->redirect($url);
 }
Example #7
0
 public static function getWeight()
 {
     $weight = 0;
     $weightObject = K2StoreFactory::getWeightObject();
     JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_k2store/models');
     $model = JModelLegacy::getInstance('Mycart', 'K2StoreModel');
     $products = $model->getDataNew();
     foreach ($products as $product) {
         if ($product['shipping']) {
             $weight += $weightObject->convert($product['weight_total'], $product['weight_class_id'], self::getStoreAddress()->config_weight_class_id);
         }
     }
     return $weight;
 }