Beispiel #1
0
 function display($tpl = null)
 {
     //run the update if auto update is enabled
     require_once JPATH_SITE . '/components/com_k2store/helpers/cart.php';
     $storeprofile = K2StoreHelperCart::getStoreAddress();
     if ($storeprofile->config_currency_auto) {
         $model = $this->getModel('currencies');
         $model->updateCurrencies();
     }
     // Get data from the model
     $this->items = $this->get('Items');
     $this->pagination = $this->get('Pagination');
     // inturn calls getState in parent class and populateState() in model
     $this->state = $this->get('State');
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode('<br />', $errors));
         return false;
     }
     //add toolbar
     $this->addToolBar();
     $toolbar = new K2StoreToolBar();
     $toolbar->renderLinkbar();
     // Display the template
     parent::display($tpl);
     $this->setDocument();
 }
Beispiel #2
0
 function save($key = null, $urlVar = null)
 {
     if (parent::save($key = null, $urlVar = null)) {
         require_once JPATH_SITE . '/components/com_k2store/helpers/cart.php';
         $storeprofile = K2StoreHelperCart::getStoreAddress();
         if ($storeprofile->config_currency_auto) {
             $model = $this->getModel('currencies');
             $model->updateCurrencies(true);
         }
     }
 }
Beispiel #3
0
 public function checkCurrency()
 {
     $db = JFactory::getDbo();
     require_once JPATH_SITE . '/components/com_k2store/helpers/cart.php';
     $storeProfile = K2StoreHelperCart::getStoreAddress();
     //first check if the currency table has a default records at least.
     $query = $db->getQuery(true)->select('*')->from('#__k2store_currency');
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     if (count($rows) < 1) {
         //no records found. Dumb default data
         JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2store/tables');
         $item = JTable::getInstance('Currency', 'Table');
         $item->currency_title = 'US Dollar';
         $item->currency_code = 'USD';
         $item->currency_position = 'pre';
         $item->currency_symbol = '$';
         $item->currency_num_decimals = '2';
         $item->currency_decimal = '.';
         $item->currency_thousands = ',';
         $item->currency_value = '1.00000';
         //default currency is one always
         $item->currency_modified = JFactory::getDate()->toSql();
         $item->state = 1;
         $item->store();
     }
     $query = $db->getQuery(true)->select('*')->from('#__k2store_currency')->where('currency_value=' . $db->q('1.00000'));
     $db->setQuery($query);
     try {
         $currency = $db->loadObject();
     } catch (Exception $e) {
         //do nothing
     }
     //if currency is empty, set it
     if (empty($storeProfile->config_currency) || JString::strlen($storeProfile->config_currency) < 3) {
         if ($currency) {
             $sql = $db->getQuery(true)->update('#__k2store_storeprofiles')->set('config_currency=' . $db->q($currency->currency_code))->where('store_id=' . $db->q($storeProfile->store_id));
             $db->setQuery($sql);
             $db->execute();
         }
     }
     return true;
 }
Beispiel #4
0
 public function __construct()
 {
     require_once JPATH_SITE . '/components/com_k2store/helpers/cart.php';
     $storeprofile = K2StoreHelperCart::getStoreAddress();
     $this->config = $storeprofile;
     $this->session = JFactory::getSession();
     $this->input = JFactory::getApplication()->input;
     $rows = self::getCurrencyList();
     foreach ($rows as $result) {
         $this->currencies[$result['currency_code']] = $result;
     }
     $currency = $this->input->get('currency');
     if (isset($currency) && array_key_exists($currency, $this->currencies)) {
         $this->set($currency);
     } elseif ($this->session->has('currency', 'k2store') && array_key_exists($this->session->get('currency', '', 'k2store'), $this->currencies)) {
         $this->set($this->session->get('currency', '', 'k2store'));
     } else {
         $this->set($this->config->config_currency);
     }
 }
Beispiel #5
0
 public function __construct()
 {
     $app = JFactory::getApplication();
     $config = JComponentHelper::getParams('com_k2store');
     $session = JFactory::getSession();
     $storeAddress = K2StoreHelperCart::getStoreAddress();
     if ($session->has('shipping_country_id', 'k2store') || $session->has('shipping_zone_id', 'k2store')) {
         $this->setShippingAddress($session->get('shipping_country_id', '', 'k2store'), $session->get('shipping_zone_id', '', 'k2store'));
     } elseif ($config->get('config_tax_default') == 'shipping') {
         $this->setShippingAddress($storeAddress->country_id, $storeAddress->zone_id);
     }
     if ($session->has('billing_country_id', 'k2store') || $session->has('billing_zone_id', 'k2store')) {
         $this->setBillingAddress($session->get('billing_country_id', '', 'k2store'), $session->get('billing_zone_id', '', 'k2store'));
     } elseif ($config->get('config_tax_default') == 'billing') {
         $this->setBillingAddress($storeAddress->country_id, $storeAddress->zone_id);
     }
     // intialize session data with store's country and zone ids
     //$session->set('k2store_address', null);
     //$this->intializeStoreAddress();
     $this->setStoreAddress($storeAddress->country_id, $storeAddress->zone_id);
 }
Beispiel #6
0
 public static function getItems()
 {
     $list = array();
     $k2params = JComponentHelper::getParams('com_k2store');
     if (K2StoreHelperCart::hasProducts()) {
         require_once JPATH_SITE . '/components/com_k2store/models/mycart.php';
         $cart_model = new K2StoreModelMyCart();
         $totals = $cart_model->getTotals();
         $product_count = K2StoreHelperCart::countProducts();
         if ($k2params->get('auto_calculate_tax', 1)) {
             $total = $totals['total'];
         } else {
             $total = $totals['total_without_tax'];
         }
         $list['total'] = $total;
         $list['product_count'] = $product_count;
         //$html = JText::sprintf('k2store_CART_TOTAL', $product_count, k2storePrices::number($total));
     } else {
         $list['total'] = 0;
         $list['product_count'] = 0;
         //$html = JText::_('k2store_NO_ITEMS_IN_CART');
     }
     return $list;
 }
Beispiel #7
0
 /**
  * This method occurs after payment is attempted,
  * and fires the onPostPayment plugin event
  *
  * @return unknown_type
  */
 function confirmPayment()
 {
     $app = JFactory::getApplication();
     $orderpayment_type = $app->input->getString('orderpayment_type');
     // Get post values
     $values = $app->input->getArray($_POST);
     //backward compatibility for payment plugins
     foreach ($values as $name => $value) {
         $app->input->set($name, $value);
     }
     //set the guest mail to null if it is present
     //check if it was a guest checkout
     $account = $this->session->get('account', 'register', 'k2store');
     // get the order_id from the session set by the prePayment
     $orderpayment_id = (int) $app->getUserState('k2store.orderpayment_id');
     if ($account != 'guest') {
         $order_link = 'index.php?option=com_k2store&view=orders&task=view&id=' . $orderpayment_id;
     } else {
         $guest_token = $app->getUserState('k2store.order_token');
         $order_link = 'index.php?option=com_k2store&view=orders&task=view';
         //assign to another session variable, for security reasons
         if ($this->session->has('guest', 'k2store')) {
             $guest = $this->session->get('guest', array(), 'k2store');
             $this->session->set('guest_order_email', $guest['billing']['email']);
             $this->session->set('guest_order_token', $guest_token);
         }
     }
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('k2store');
     $html = "";
     $order = $this->_order;
     $order->load(array('id' => $orderpayment_id));
     // free product? set the state to confirmed and save the order.
     if (!empty($orderpayment_id) && (double) $order->order_total == (double) '0.00') {
         $order->order_state = trim(JText::_('CONFIRMED'));
         $order->order_state_id = '1';
         // PAYMENT RECEIVED.
         if ($order->save()) {
             // remove items from cart
             K2StoreHelperCart::removeOrderItems($order->id);
         }
         //send email
         require_once JPATH_SITE . '/components/com_k2store/helpers/orders.php';
         K2StoreOrdersHelper::sendUserEmail($order->user_id, $order->order_id, $order->transaction_status, $order->order_state, $order->order_state_id);
     } else {
         // get the payment results from the payment plugin
         $results = $dispatcher->trigger("onK2StorePostPayment", array($orderpayment_type, $values));
         // Display whatever comes back from Payment Plugin for the onPrePayment
         for ($i = 0; $i < count($results); $i++) {
             $html .= $results[$i];
         }
         // re-load the order in case the payment plugin updated it
         $order->load(array('id' => $orderpayment_id));
     }
     // $order_id would be empty on posts back from Paypal, for example
     if (isset($orderpayment_id)) {
         //unset a few things from the session.
         $this->session->clear('shipping_method', 'k2store');
         $this->session->clear('shipping_methods', 'k2store');
         $this->session->clear('shipping_values', 'k2store');
         $this->session->clear('payment_method', 'k2store');
         $this->session->clear('payment_methods', 'k2store');
         $this->session->clear('payment_values', 'k2store');
         $this->session->clear('guest', 'k2store');
         $this->session->clear('customer_note', 'k2store');
         //save the coupon to the order_coupons table for tracking and unset session.
         if ($this->session->has('coupon', 'k2store')) {
             $coupon_info = K2StoreHelperCart::getCoupon($this->session->get('coupon', '', 'k2store'));
             if ($coupon_info) {
                 $order_coupons = JTable::getInstance('OrderCoupons', 'Table');
                 $order_coupons->set('coupon_id', $coupon_info->coupon_id);
                 $order_coupons->set('orderpayment_id', $orderpayment_id);
                 $order_coupons->set('customer_id', JFactory::getUser()->id);
                 $order_coupons->set('amount', $order->order_discount);
                 $order_coupons->set('created_date', JFactory::getDate()->toSql());
                 $order_coupons->store();
             }
         }
         //clear the session
         $this->session->clear('coupon', 'k2store');
         //trigger onAfterOrder plugin event
         $results = $dispatcher->trigger("onK2StoreAfterPayment", array($order));
         foreach ($results as $result) {
             $html .= $result;
         }
         // Set display
         $view = $this->getView('checkout', 'html');
         $view->setLayout('postpayment');
         $view->set('_doTask', true);
         $params = $params = JComponentHelper::getParams('com_k2store');
         if ($params->get('show_postpayment_orderlink', 1)) {
             $view->assign('order_link', JRoute::_($order_link));
         }
         $view->assign('plugin_html', $html);
         // Get and Set Model
         $model = $this->getModel('checkout');
         $view->setModel($model, true);
         $view->display();
     }
     return;
 }
    static function k2Store($item)
    {
        // preparing the output array
        $output = array('cart' => '', 'price' => '');
        // if the settings exists
        if (is_file(JPATH_SITE . '/components/com_k2store/helpers/cart.php')) {
            require_once JPATH_SITE . '/components/com_k2store/helpers/cart.php';
            // get product data
            $item_plugins_data = json_decode($item['plugins']);
            // output for the cart
            $output['cart'] = '<form action="index.php?option=com_k2store&amp;view=mycart" method="post" class="k2storeCartForm1 nspK2StoreCartForm" id="k2storeadminForm_' . $item['id'] . '" name="k2storeadminForm_' . $item['id'] . '" enctype="multipart/form-data">							
				<div id="add_to_cart_12" class="k2store_add_to_cart">
			        <input type="hidden" id="k2store_product_id" name="product_id" value="' . $item['id'] . '">
		
			        ' . JHTML::_('form.token') . '				        
			        <input type="hidden" name="return" value="' . base64_encode(JUri::getInstance()->toString()) . '">
			        <input value="Add to cart" type="submit" class="k2store_cart_button btn btn-primary">
			    </div>
			
				<div class="k2store-notification" style="display: none;">
						<div class="message"></div>
						<div class="cart_link"><a class="btn btn-success" href="index.php?option=com_k2store&amp;view=mycart">View Cart</a></div>
						<div class="cart_dialogue_close" onclick="jQuery(this).parent().slideUp().hide();">x</div>
				</div>
				
				<div class="error_container">
					<div class="k2product"></div>
					<div class="k2stock"></div>
				</div>
			
				<input type="hidden" name="product_qty" value="1">
				<input type="hidden" name="option" value="com_k2store">
				<input type="hidden" name="view" value="mycart">
				<input type="hidden" id="task" name="task" value="add">
			</form>';
            // output for the price
            $output['price'] = '';
            // getting the necessary data
            $price = $item_plugins_data->k2storeitem_price;
            $tax = $item_plugins_data->k2storeitem_tax;
            $special_price = 0;
            // getting the special price if exists
            if (isset($item_plugins_data->k2storespecial_price)) {
                $special_price = $item_plugins_data->k2storespecial_price;
            }
            // generate the basic price
            $base_price = K2StoreHelperCart::dispayPriceWithTax($price, $tax, 1);
            // check if the special price exists
            if ($special_price > 0.0) {
                $base_price = '<strike>' . $base_price . '</strike> ' . K2StoreHelperCart::dispayPriceWithTax($special_price, $tax, 1);
            }
            // set the final output of the price
            $output['price'] = '<span class="nspK2StorePrice">' . $base_price . '</span>';
        }
        // return the output array
        return $output;
    }
Beispiel #9
0
 function createInvoiceNumber($order_id)
 {
     $db = JFactory::getDbo();
     $status = true;
     $invoice = new JObject();
     $invoice->number = 0;
     $invoice->prefix = '';
     require_once JPATH_SITE . '/components/com_k2store/helpers/cart.php';
     $store = K2StoreHelperCart::getStoreAddress();
     if (!isset($store->store_invoice_prefix) || empty($store->store_invoice_prefix)) {
         //backward compatibility. If no prefix is set, retain the invoice number is the table primary key.
         $status = false;
     }
     if ($status) {
         //get the last row
         $query = $db->getQuery(true)->select('MAX(invoice_number) AS invoice_number')->from('#__k2store_orders')->where('invoice_prefix=' . $db->q($store->store_invoice_prefix));
         $db->setQuery($query);
         $row = $db->loadObject();
         if (isset($row->invoice_number) && $row->invoice_number) {
             $invoice_number = $row->invoice_number + 1;
         } else {
             $invoice_number = 1;
         }
         $invoice->number = $invoice_number;
         $invoice->prefix = $store->store_invoice_prefix;
     }
     return $invoice;
 }
Beispiel #10
0
 /**
  * Calculates the per_order coupon discount for the order
  * and the total post-tax/shipping discount
  * and sets order->order_discount
  *
  * @return unknown_type
  */
 function calculateDiscountTotals()
 {
     $this->_taxes = K2StoreHelperCart::getTaxes();
     $session = JFactory::getSession();
     $tax = new K2StoreTax();
     JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_k2store/models');
     $model = JModelLegacy::getInstance('MyCart', 'K2StoreModel');
     $products = $model->getDataNew();
     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 = K2StoreHelperCart::getSubTotal();
             } else {
                 $sub_total = 0;
                 foreach ($products as $product) {
                     if (in_array($product['product_id'], $coupon_info->product)) {
                         $sub_total += $product['total'];
                     }
                 }
             }
             if ($coupon_info->value_type == 'F') {
                 $coupon_info->value = min($coupon_info->value, $sub_total);
             }
             foreach ($products as $product) {
                 $discount = 0;
                 if (!$coupon_info->product) {
                     $status = true;
                 } else {
                     if (in_array($product['product_id'], $coupon_info->product)) {
                         $status = true;
                     } else {
                         $status = false;
                     }
                 }
                 if ($status) {
                     if ($coupon_info->value_type == 'F') {
                         $discount = $coupon_info->value * ($product['total'] / $sub_total);
                     } elseif ($coupon_info->value_type == 'P') {
                         $discount = $product['total'] / 100 * $coupon_info->value;
                     }
                     if ($product['tax_profile_id']) {
                         $tax_rates = $tax->getRateArray($product['total'] - ($product['total'] - $discount), $product['tax_profile_id']);
                         foreach ($tax_rates as $tax_rate) {
                             //	if ($tax_rate['value_type'] == 'P') {
                             $this->_taxes[$tax_rate['taxrate_id']] -= $tax_rate['amount'];
                             //	}
                         }
                     }
                 }
                 $discount_total += $discount;
             }
         }
     }
     // store the total amount of the discount
     //set the total as equal to the order_subtotal + order_tax if its greater than the sum of the two
     $this->order_discount = $discount_total > $this->order_subtotal + $this->order_tax ? $this->order_subtotal + $this->order_tax : $discount_total;
 }
Beispiel #11
0
 public static function getStock($product_id)
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('*');
     $query->from('#__k2store_products');
     $query->where('product_id=' . $db->quote($product_id));
     $db->setQuery($query);
     $stock = $db->loadObject();
     if (!isset($stock) || K2STORE_PRO != 1) {
         $stock = JTable::getInstance('Products', 'Table');
     }
     //prepare data. We may have some settings in the store global
     require_once JPATH_SITE . '/components/com_k2store/helpers/cart.php';
     $store_config = K2StoreHelperCart::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;
 }
Beispiel #12
0
 protected function _loadCart($item, $params)
 {
     $lang = JFactory::getLanguage();
     $lang->load('com_k2store');
     if (empty($item->id) || is_int($item->id == false)) {
         return '';
     }
     //$product = K2StorePrices::_getK2StoreVars($item->id);
     $product = K2StoreHelperCart::getItemInfo($item->id);
     // show/hide add to cart button
     $output = '';
     if (isset($product->item_enabled) && $product->item_enabled == 1) {
         $output = K2StoreHelperCart::getAjaxCart($item);
     }
     return $output;
 }
Beispiel #13
0
 function display($field, $value, $map, $inside, $options = '', $test = false, $allFields = null, $allValues = null)
 {
     $app = JFactory::getApplication();
     require_once JPATH_SITE . '/components/com_k2store/helpers/cart.php';
     $store = K2StoreHelperCart::getStoreAddress();
     $stateId = $currentZoneId = $store->zone_id > 0 ? $store->zone_id : '';
     $country_id = $store->country_id > 0 ? $store->country_id : '';
     //if no default value was set in the fields, then use the country id set in the store profile.
     if (empty($field->field_default)) {
         $defaultCountry = $country_id;
     }
     if (empty($value)) {
         $value = $field->field_default;
     }
     if ($field->field_options['zone_type'] == 'country') {
         if (isset($defaultCountry)) {
             $field->field_default = $defaultCountry;
         }
     } elseif ($field->field_options['zone_type'] == 'zone') {
         $stateId = str_replace(array('[', ']'), array('_', ''), $map);
         $dropdown = '';
         if ($allFields != null) {
             $country = null;
             foreach ($allFields as $f) {
                 if ($f->field_type == 'zone' && !empty($f->field_options['zone_type']) && $f->field_options['zone_type'] == 'country') {
                     $key = $f->field_namekey;
                     if (!empty($allValues->{$key})) {
                         $country = $allValues->{$key};
                     } else {
                         $country = $f->field_default;
                     }
                     break;
                 }
             }
             //no country id, then load it based on the zone default.
             if (empty($country) && isset($field->field_default)) {
                 JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2store/tables');
                 $table = JTable::getInstance('zone', 'Table');
                 if ($table->load($field->field_default)) {
                     $country = $table->country_id;
                 }
             }
             //still no. Set it to store default.
             if (empty($country)) {
                 $country = $store->country_id;
             }
             if (!empty($country)) {
                 $countryType = new k2storeCountryType();
                 $countryType->type = 'zone';
                 $countryType->country_id = $country;
                 $countryType->published = true;
                 $dropdown = $countryType->displayZone($map, $value, true);
             }
         }
         $html = '<span id="' . $stateId . '_container">' . $dropdown . '</span>' . '<input type="hidden" id="' . $stateId . '_default_value" name="' . $stateId . '_default_value" value="' . $value . '"/>';
         return $html;
     }
     return parent::display($field, $value, $map, $inside, $options, $test, $allFields, $allValues);
 }
Beispiel #14
0
 /**
  * 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->includeK2StoreTables();
     $this->includeCustomTables();
     $this->includeCustomModel('ShippingMethods');
     $this->includeCustomModel('ShippingRates');
     // TODO Give this better error reporting capabilities
     //JModelLegacy::addIncludePath( JPATH_ADMINISTRATOR.'/components/com_k2store/models' );
     $model = JModelLegacy::getInstance('ShippingRates', 'K2StoreModel');
     $model->setState('filter_shippingmethod', $shipping_method_id);
     $model->setState('filter_geozone', $geozone_id);
     //initialise cart helper
     $cart_helper = new K2StoreHelperCart();
     $product = $cart_helper->getItemInfo($product_id);
     if (empty($product->product_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];
 }
Beispiel #15
0
 function getTotals()
 {
     $app = JFactory::getApplication();
     $session = JFactory::getSession();
     $tax = new K2StoreTax();
     $products = $this->getDataNew();
     $total_data = array();
     $total = 0;
     //products
     $total_data['products'] = $products;
     //sub total
     $total_data['subtotal'] = K2StoreHelperCart::getSubtotal();
     $total += $total_data['subtotal'];
     //taxes
     $tax_data = array();
     $taxes = K2StoreHelperCart::getTaxes();
     //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 = K2StoreHelperCart::getSubTotal();
             } else {
                 $sub_total = 0;
                 foreach ($products as $product) {
                     if (in_array($product['product_id'], $coupon_info->product)) {
                         $sub_total += $product['total'];
                     }
                 }
             }
             if ($coupon_info->value_type == 'F') {
                 $coupon_info->value = min($coupon_info->value, $sub_total);
             }
             foreach ($products as $product) {
                 $discount = 0;
                 if (!$coupon_info->product) {
                     $status = true;
                 } else {
                     if (in_array($product['product_id'], $coupon_info->product)) {
                         $status = true;
                     } else {
                         $status = false;
                     }
                 }
                 if ($status) {
                     if ($coupon_info->value_type == 'F') {
                         $discount = $coupon_info->value * ($product['total'] / $sub_total);
                     } elseif ($coupon_info->value_type == 'P') {
                         $discount = $product['total'] / 100 * $coupon_info->value;
                     }
                     if ($product['tax_profile_id']) {
                         $tax_rates = $this->tax->getRateArray($product['total'] - ($product['total'] - $discount), $product['tax_profile_id']);
                         foreach ($tax_rates as $tax_rate) {
                             //	if ($tax_rate['value_type'] == 'P') {
                             $taxes[$tax_rate['taxrate_id']] -= $tax_rate['amount'];
                             //	}
                         }
                     }
                 }
                 $discount_total += $discount;
             }
             $total_data['coupon'] = array('title' => JText::sprintf('K2STORE_COUPON_TITLE', $session->get('coupon', '', 'k2store')), 'value' => -$discount_total);
             //$total_data['coupon'] = $coupon_data;
             //less the coupon discount in the total
             $total -= $discount_total;
         }
     }
     if ($session->has('shipping_values', 'k2store')) {
         $shipping = $session->get('shipping_values', array(), 'k2store');
         if (count($shipping) && isset($shipping['shipping_name'])) {
             $total_data['shipping_amount'] = $shipping['shipping_price'] + $shipping['shipping_extra'];
             $total_data['shipping_tax'] = $shipping['shipping_tax'];
             $total_data['shipping_total'] = $shipping['shipping_price'] + $shipping['shipping_extra'] + $shipping['shipping_tax'];
             $total_data['shipping_name'] = $shipping['shipping_name'];
             $total += $total_data['shipping_total'];
         }
     }
     $total_data['total_without_tax'] = $total;
     //taxes
     foreach ($taxes as $key => $value) {
         if ($value > 0) {
             $tax_data[] = array('title' => $this->tax->getRateName($key), 'percent' => $tax->getPercent($key), 'value' => $value);
             $total += $value;
         }
     }
     $total_data['taxes'] = $tax_data;
     $total_data['total'] = $total;
     return $total_data;
 }
Beispiel #16
0
# copyright Copyright (C) 2012 Weblogicxindia.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://k2store.org
# Technical Support:  Forum - http://k2store.org/forum/index.html
-------------------------------------------------------------------------*/
// no direct access
defined('_JEXEC') or die('Restricted access');
require_once JPATH_ADMINISTRATOR . '/components/com_k2store/library/k2item.php';
require_once JPATH_SITE . '/components/com_k2store/helpers/cart.php';
require_once JPATH_ADMINISTRATOR . '/components/com_k2store/library/inventory.php';
$items = $this->cartobj;
//$mysubtotal = K2StoreHelperCart::getSubtotal();
//$state = $this->state;
$quantities = array();
$action = JRoute::_('index.php');
$storeAddress = K2StoreHelperCart::getStoreAddress();
if (isset($storeAddress->config_default_category) && $storeAddress->config_default_category != 0) {
    require_once JPATH_SITE . '/components/com_k2/helpers/route.php';
    $continue_shopping_url = JRoute::_(K2HelperRoute::getCategoryRoute($storeAddress->config_default_category));
}
if (isset($storeAddress->config_continue_shopping_url) && JString::strlen($storeAddress->config_continue_shopping_url) > 5) {
    $continue_shopping_url = $storeAddress->config_continue_shopping_url;
}
$checkout_url = JRoute::_('index.php?option=com_k2store&view=checkout');
?>
<div class="k2store">
<div class="row-fluid">
<div class="span12">
<?php 
if (!isset($this->remove)) {
    ?>
Beispiel #17
0
 function validateCoupon()
 {
     $app = JFactory::getApplication();
     $coupon_info = K2StoreHelperCart::getCoupon($app->input->getString('coupon', ''));
     if ($coupon_info) {
         return true;
     } else {
         throw new Exception(JText::_('K2STORE_COUPON_INVALID'));
         return false;
     }
 }
 function _process()
 {
     /*
      * perform initial checks
      */
     if (!JRequest::checkToken()) {
         return $this->_renderHtml(JText::_('Invalid Token'));
     }
     $app = JFactory::getApplication();
     $data = $app->input->getArray($_POST);
     $json = array();
     $errors = array();
     // get order information
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2store/tables');
     $order = JTable::getInstance('Orders', 'Table');
     $order->load($data['orderpayment_id']);
     if (empty($order->order_id)) {
         $json['error'] = JText::_('K2STORE_CHECKOUTAPIPAYMENT_INVALID_ORDER');
     }
     if (empty($this->secret_key) || empty($this->publishable_key)) {
         $json['error'] = JText::_('K2STORE_CHECKOUTAPIPAYMENT_MESSAGE_MISSING_CONFIG');
     }
     if (!$json) {
         require_once JPATH_SITE . '/components/com_k2store/helpers/utilities.php';
         //get the order info from order info table
         $orderinfo = JTable::getInstance('Orderinfo', 'Table');
         $orderinfo->load(array('order_id' => $order->order_id));
         $currency_values = $this->getCurrency($order);
         $amount = $this->getAmount($order->orderpayment_amount, $currency_values['currency_code'], $currency_values['currency_value'], $currency_values['convert']);
         $amountCents = $amount * 100;
         $config = array();
         $config['authorization'] = $this->secret_key;
         $config['mode'] = $this->endpoint;
         $config['postedParam'] = array('email' => $orderinfo->user_email, 'value' => $amountCents, 'currency' => $order->currency_code, 'shippingDetails' => array('addressLine1' => $orderinfo->shipping_address_1, 'addressLine2' => $orderinfo->shipping_address_2, 'Postcode' => $orderinfo->shipping_zip, 'Country' => $orderinfo->shipping_country_name, 'City' => $orderinfo->shipping_city, 'State' => $orderinfo->shipping_zone_name, 'Phone' => !empty($orderinfo->shipping_phone_1) ? $orderinfo->shipping_phone_1 : $orderinfo->shipping_phone_2, 'recipientname' => $orderinfo->shipping_first_name . ' ' . $orderinfo->shipping_first_name));
         if ($this->trans_type == 'Authorize_Capture') {
             $config = array_merge($this->captureConfig(), $config);
         } else {
             $config = array_merge($this->authorizeConfig(), $config);
         }
         if ($this->ispci == "Yes") {
             $config['postedParam']['card']['name'] = $data['cardname'];
             $config['postedParam']['card']['number'] = $data['cardnum'];
             $config['postedParam']['card']['expiryMonth'] = $data['cardmonth'];
             $config['postedParam']['card']['expiryYear'] = $data['cardyear'];
             $config['postedParam']['card']['cvv'] = $data['cardcvv'];
             $config['postedParam']['card']['billingDetails']['addressLine1'] = $orderinfo->billing_address_1;
             $config['postedParam']['card']['billingDetails']['addressLine2'] = $orderinfo->billing_address_2;
             $config['postedParam']['card']['billingDetails']['postcode'] = $orderinfo->billing_zip;
             $config['postedParam']['card']['billingDetails']['country'] = $orderinfo->billing_country_name;
             $config['postedParam']['card']['billingDetails']['city'] = $orderinfo->billing_city;
             $config['postedParam']['card']['billingDetails']['city'] = $orderinfo->billing_zone_name;
             $config['postedParam']['card']['billingDetails']['phone'] = !empty($orderinfo->billing_phone_1) ? $orderinfo->billing_phone_1 : $orderinfo->billing_phone_2;
         } else {
             $config['postedParam']['email'] = $data['cko_cc_email'];
             $config['postedParam']['cardToken'] = $data['cko_cc_token'];
         }
         $respondCharge = $this->placeOrder($config);
         if ($respondCharge->isValid()) {
             if (preg_match('/^1[0-9]+$/', $respondCharge->getResponseCode())) {
                 $order->order_state_id = 1;
                 $order->order_state = JText::_('K2STORE_CONFIRMED');
             } else {
                 $errMsg = JText::_('K2STORE_CHECKOUTAPI_MESSAGE_TRANSACTION_UNSUCCESSFUL') . $respondCharge->getResponseMessage();
                 $order->order_state_id = 3;
                 $order->order_state = JText::_('K2STORE_DECLINED');
                 $errors[] = $errMsg;
                 $this->_log($errMsg, 'Error Message');
             }
         } else {
             $errMsg = JText::_('K2STORE_CHECKOUTAPI_MESSAGE_TRANSACTION_UNSUCCESSFUL') . $respondCharge->getExceptionState()->getErrorMessage();
             $order->order_state_id = 3;
             $order->order_state = JText::_('K2STORE_FAILED');
             $errors[] = $errMsg;
             $this->_log($errMsg, 'Error Message');
         }
         if (!$order->save()) {
             $errors[] = $order->getError();
         }
         if (empty($errors)) {
             $json['success'] = JText::_($this->params->get('onafterpayment', ''));
             $json['redirect'] = JRoute::_('index.php?option=com_k2store&view=checkout&task=confirmPayment&orderpayment_type=' . $this->_element . '&paction=display');
             K2StoreHelperCart::removeOrderItems($order->id);
         }
         if (count($errors)) {
             $json['error'] = implode("\n", $errors);
         }
     }
     return $json;
 }
Beispiel #19
0
 public function updateCurrencies($force = false)
 {
     if (extension_loaded('curl')) {
         $data = array();
         require_once JPATH_SITE . '/components/com_k2store/helpers/cart.php';
         $storeprofile = K2StoreHelperCart::getStoreAddress();
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('*')->from('#__k2store_currency')->where('currency_code !=' . $db->q($storeprofile->config_currency));
         if ($force) {
             $query->where('currency_modified=' . $db->q(date('Y-m-d H:i:s', strtotime('-1 day'))));
         }
         $db->setQuery($query);
         $rows = $db->loadAssocList();
         foreach ($rows as $result) {
             $data[] = $storeprofile->config_currency . $result['currency_code'] . '=X';
         }
         $curl = curl_init();
         curl_setopt($curl, CURLOPT_URL, 'http://download.finance.yahoo.com/d/quotes.csv?s=' . implode(',', $data) . '&f=sl1&e=.csv');
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         $content = curl_exec($curl);
         curl_close($curl);
         $lines = explode("\n", trim($content));
         foreach ($lines as $line) {
             $currency = utf8_substr($line, 4, 3);
             $value = utf8_substr($line, 11, 6);
             if ((double) $value) {
                 $query = $db->getQuery(true);
                 $query->update('#__k2store_currency')->set('currency_value =' . $db->q((double) $value))->set('currency_modified=' . $db->q(date('Y-m-d H:i:s')))->where('currency_code=' . $db->q($currency));
                 $db->setQuery($query);
                 $db->query();
             }
         }
         //update the default currency
         $query = $db->getQuery(true);
         $query->update('#__k2store_currency')->set('currency_value =' . $db->q('1.00000'))->set('currency_modified=' . $db->q(date('Y-m-d H:i:s')))->where('currency_code=' . $db->q($storeprofile->config_currency));
         $db->setQuery($query);
         $db->query();
     }
 }
Beispiel #20
0
 /**
  * Processes the payment form
  * and returns HTML to be displayed to the user
  * generally with a success/failed message
  *
  * @param $data     array       form post data
  * @return string   HTML to display
  */
 function _postPayment($data)
 {
     // Process the payment
     $app = JFactory::getApplication();
     $vars = new JObject();
     $html = '';
     $orderpayment_id = $app->input->getInt('orderpayment_id');
     // load the orderpayment record and set some values
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2store/tables');
     $orderpayment = JTable::getInstance('Orders', 'Table');
     $orderpayment->load($orderpayment_id);
     if ($orderpayment->id == $orderpayment_id) {
         $payment_status = $this->getPaymentStatus($this->params->get('payment_status', 4));
         $orderpayment->transaction_status = $payment_status;
         $orderpayment->order_state = $payment_status;
         $orderpayment->order_state_id = $this->params->get('payment_status', 4);
         // DEFAULT: PENDING
         // save the orderpayment
         if ($orderpayment->save()) {
             JLoader::register('K2StoreHelperCart', JPATH_SITE . '/components/com_k2store/helpers/cart.php');
             // remove items from cart
             K2StoreHelperCart::removeOrderItems($orderpayment->id);
         } else {
             $errors[] = $orderpayment->getError();
         }
         // let us inform the user that the order is successful
         require_once JPATH_SITE . '/components/com_k2store/helpers/orders.php';
         K2StoreOrdersHelper::sendUserEmail($orderpayment->user_id, $orderpayment->order_id, $orderpayment->transaction_status, $orderpayment->order_state, $orderpayment->order_state_id);
         $vars->onafterpayment_text = $this->params->get('onafterpayment', '');
         // display the layout
         $html = $this->_getLayout('postpayment', $vars);
         // append the article with cash payment information
         $html .= $this->_displayArticle();
     }
     return $html;
 }
Beispiel #21
0
                ?>
"><?php 
                echo stripslashes($db->escape(JText::_($option_value['optionvalue_name'])));
                ?>
            <?php 
                if ($option_value['product_optionvalue_price'] > 0) {
                    ?>
                <?php 
                    //get the tax
                    $tax = $this->tax_class->getProductTax($option_value['product_optionvalue_price'], $this->item->product_id);
                    ?>
            	(<?php 
                    echo $option_value['product_optionvalue_prefix'];
                    ?>
            	<?php 
                    echo K2StoreHelperCart::dispayPriceWithTax($option_value['product_optionvalue_price'], $tax, $this->params->get('price_display_options', 1));
                    ?>
            	)
            	<?php 
                }
                ?>
          </label>
          <br />
          <?php 
            }
            ?>
        </div>
        <br />
        <?php 
        }
        ?>
Beispiel #22
0
            if ($item->special_price > 0.0) {
                echo '</strike>';
            }
            ?>
				</span>
			
				<!--special price-->
			  <?php 
            if ($item->special_price > 0.0) {
                ?>
			    <span id="product_special_price_<?php 
                echo $item->product_id;
                ?>
" class="product_special_price">
			    	<?php 
                echo K2StoreHelperCart::dispayPriceWithTax($item->special_price, $item->sp_tax, $this->params->get('price_display_options', 1));
                ?>
			    </span>
			  <?php 
            }
            ?>
		
			<?php 
        }
        ?>
		
		
		<!-- sku -->
		
		  <?php 
        if ($this->params->get('show_sku_field', 0)) {
Beispiel #23
0
} else {
    ?>
		<input type="hidden" name="product_qty" value="<?php 
    echo $item->product_quantity;
    ?>
" size="5" />	
  <?php 
}
?>
  <!--attribute options-->
			<div id='product_attributeoptions_<?php 
echo $item->product_id;
?>
' class="product_attributeoptions">
			    <?php 
$default = K2StoreHelperCart::getDefaultAttributeOptions($this->attributes);
foreach ($this->attributes as $attribute) {
    $attribs = array('class' => 'inputbox', 'size' => '1');
    ?>
			        <div class="pao" id='productattributeoption_<?php 
    echo $attribute->productattribute_id;
    ?>
'>
			        <?php 
    echo "<span class='attribute_title'>" . $attribute->productattribute_name . "&nbsp;";
    $required = K2StoreSelect::getAttributeRequired($attribute->productattribute_id);
    if ($required) {
        $attribs = array('class' => 'inputbox required', 'size' => '1');
        echo '*';
    } else {
        $attribs = array('class' => 'inputbox', 'size' => '1');
Beispiel #24
0
    ?>
</th>
		<th><?php 
    echo JText::_('K2STORE_FILE_DESCRIPTION');
    ?>
</th>
		<th><?php 
    echo JText::_('K2STORE_DOWNLOAD_LINK');
    ?>
</th>
	</thead>
	<?php 
    foreach ($this->files as $files) {
        foreach ($files as $file) {
            $file_link = $this->model->getLink($file->id, $file->itemID, $file->order_id);
            $product = K2StoreHelperCart::getItemInfo($file->product_id);
            ?>
	<tr>
		<td><?php 
            echo $file->order_id;
            ?>
</td>
		<td><?php 
            echo $product->product_name;
            ?>
</td>
		<td><?php 
            echo $file->title;
            ?>
</td>
		<td><?php 
Beispiel #25
0
 /**
  * Processes the payment form
  * and returns HTML to be displayed to the user
  * generally with a success/failed message
  *
  * @param $data     array       form post data
  * @return string   HTML to display
  */
 function _postPayment($data)
 {
     // Process the payment
     $vars = new JObject();
     $orderpayment_id = JRequest::getVar('orderpayment_id');
     $offline_payment_method = JRequest::getVar('offline_payment_method');
     $formatted = array('offline_payment_method' => $offline_payment_method);
     // load the orderpayment record and set some values
     JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2store' . DS . 'tables');
     $orderpayment = JTable::getInstance('Orders', 'Table');
     //remove this after live.
     //$orderpayment_id = substr($orderpayment_id, 2, 3);
     $orderpayment->load($orderpayment_id);
     $orderpayment->transaction_details = implode("\n", $formatted);
     //$orderpayment->transaction_status = JText::_('Pending_Payment');
     //$orderpayment->order_state = JText::_('Pending');
     $payment_status = $this->getPaymentStatus($this->params->get('payment_status', 4));
     $orderpayment->transaction_status = $payment_status;
     $orderpayment->order_state = $payment_status;
     $orderpayment->order_state_id = $this->params->get('payment_status', 4);
     // PENDING
     // save the orderpayment
     if ($orderpayment->save()) {
         JLoader::register('K2StoreHelperCart', JPATH_SITE . '/components/com_k2store/helpers/cart.php');
         // remove items from cart
         K2StoreHelperCart::removeOrderItems($orderpayment->id);
     } else {
         $errors[] = $orderpayment->getError();
     }
     // let us inform the user that the order is successful
     require_once JPATH_SITE . '/components/com_k2store/helpers/orders.php';
     K2StoreOrdersHelper::sendUserEmail($orderpayment->user_id, $orderpayment->order_id, $orderpayment->transaction_status, $orderpayment->order_state, $orderpayment->order_state_id);
     $vars->onafterpayment_text = $this->params->get('onafterpayment', '');
     // display the layout
     $html = $this->_getLayout('postpayment', $vars);
     // append the article with offline payment information
     $html .= $this->_displayArticle();
     return $html;
 }
Beispiel #26
0
 /**
  * Processes the payment form
  * and returns HTML to be displayed to the user
  * generally with a success/failed message
  *
  * @param $data     array       form post data
  * @return string   HTML to display
  */
 function _postPayment($data)
 {
     // Process the payment
     $app = JFactory::getApplication();
     $vars = new JObject();
     $html = '';
     $orderpayment_id = $app->input->getInt('orderpayment_id');
     // load the orderpayment record and set some values
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2store/tables');
     $orderpayment = JTable::getInstance('Orders', 'Table');
     $orderpayment->load($orderpayment_id);
     if ($orderpayment->id == $orderpayment_id) {
         $bank_information = $this->params->get('bank_information', '');
         //we have to save the bank information in the customer note because that is the only field availale to display now
         //TODO: Trigger a plugin event so that you can show custom info depending on the payment plugin.
         //get the customer note. We dont want to overwrite it.
         if (JString::strlen($bank_information) > 5) {
             $customer_note = $orderpayment->customer_note;
             $html = '<br />';
             $html .= '<strong>' . JText::_('K2STORE_BANK_TRANSFER_INSTRUCTIONS') . '</strong>';
             $html .= '<br />';
             $html .= $bank_information;
             $orderpayment->customer_note = $customer_note . $html;
         }
         $payment_status = $this->getPaymentStatus($this->params->get('payment_status', 4));
         $orderpayment->transaction_status = $payment_status;
         $orderpayment->order_state = $payment_status;
         $orderpayment->order_state_id = $this->params->get('payment_status', 4);
         // DEFAULT: PENDING
         // save the orderpayment
         if ($orderpayment->save()) {
             JLoader::register('K2StoreHelperCart', JPATH_SITE . '/components/com_k2store/helpers/cart.php');
             // remove items from cart
             K2StoreHelperCart::removeOrderItems($orderpayment->id);
         } else {
             $errors[] = $orderpayment->getError();
         }
         // let us inform the user that the order is successful
         require_once JPATH_SITE . '/components/com_k2store/helpers/orders.php';
         K2StoreOrdersHelper::sendUserEmail($orderpayment->user_id, $orderpayment->order_id, $orderpayment->transaction_status, $orderpayment->order_state, $orderpayment->order_state_id);
         $vars->onafterpayment_text = $this->params->get('onafterpayment', '');
         // display the layout
         $html = $this->_getLayout('postpayment', $vars);
         // append the article with banktransfer payment information
         $html .= $this->_displayArticle();
     }
     return $html;
 }
Beispiel #27
0
 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];
 }