public static function getProducts() { JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_k2store/models'); $model = JModelLegacy::getInstance('Mycart', 'K2StoreModel'); $db = JFactory::getDbo(); //get the products from the cart $cartitems = $model->getDataNew(); //now we have to prepare this data for adding into order table object $productitems = array(); $cartitem = array(); foreach ($cartitems as $cartitem) { if ($productItem = K2StoreHelperCart::getItemInfo($cartitem['product_id'])) { //base price $price = $productItem->price; //now get special price or discounted prices, if any $price_override = K2StorePrices::getPrice($productItem->product_id, $cartitem['quantity']); if (isset($price_override) && !empty($price_override)) { $price = 0; } //$productItem->price = $productItem->product_price = $cartitem->product_price; // TODO Push this into the orders object->addItem() method? $orderItem = JTable::getInstance('OrderItems', 'Table'); $orderItem->product_id = $productItem->product_id; $orderItem->orderitem_sku = $productItem->product_sku; $orderItem->orderitem_name = $productItem->product_name; $orderItem->orderitem_quantity = $cartitem['quantity']; //original price $orderItem->orderitem_price = $price; //save product options in the json format $product_options = K2StoreHelperCart::getReadableProductOptions($cartitem['option']); $orderItem->orderitem_attributes = $db->escape($product_options->product_option_json); $orderItem->orderitem_attribute_names = $db->escape($product_options->product_option_names); $orderItem->orderitem_attributes_price = $cartitem['option_price']; /*poparada hack*/ if ($orderItem->orderitem_attributes_price > 0) { $final_price = $orderItem->orderitem_attributes_price; } else { $final_price = $orderItem->orderitem_price + $orderItem->orderitem_attributes_price; } $orderItem->orderitem_final_price = $final_price * $orderItem->orderitem_quantity; array_push($productitems, $orderItem); } } // var_dump($productitems); return $productitems; }
?> </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
/** * 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]; }
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; }
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; }
# author Ramesh Elamathi - Weblogicx India http://www.weblogicxindia.com # 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'); $options = $this->attributes; $db = JFactory::getDbo(); ?> <?php if ($options) { $product_id = $this->item->product_id; $product_info = K2StoreHelperCart::getItemInfo($product_id); $height = $product_info->item_height; $width = $product_info->item_width; ?> <div class="options"> <?php foreach ($options as $key => $option) { ?> <?php if ($option['type'] == 'select') { if ($option["option_id"] == 1) { ?> <!-- select option id = 1 --> <div id="option-<?php echo $option['product_option_id'];
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(); }