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 static function getAjaxCart($item) { require_once JPATH_ADMINISTRATOR . '/components/com_k2store/helpers/strapper.php'; K2StoreStrapper::addJS(); K2StoreStrapper::addCSS(); $app = JFactory::getApplication(); $html = ''; JLoader::register("K2StoreViewMyCart", JPATH_SITE . "/components/com_k2store/views/mycart/view.html.php"); $layout = 'addtocart'; $view = new K2StoreViewMyCart(); //$view->_basePath = JPATH_ROOT.DS.'components'.DS.'com_k2store'; $view->addTemplatePath(JPATH_SITE . '/components/com_k2store/views/mycart/tmpl'); $view->addTemplatePath(JPATH_SITE . '/templates/' . $app->getTemplate() . '/html/com_k2store/mycart'); require_once JPATH_SITE . '/components/com_k2store/models/mycart.php'; $model = new K2StoreModelMyCart(); $product_id = $item->product_id = $item->id; $view->assign('_basePath', JPATH_SITE . DS . 'components' . DS . 'com_k2store'); $view->set('_controller', 'mycart'); $view->set('_view', 'mycart'); $view->set('_doTask', true); $view->set('hidemenu', true); $view->setModel($model, true); $view->setLayout($layout); $view->assign('product_id', $product_id); $config = JComponentHelper::getParams('com_k2store'); $show_tax = $config->get('show_tax_total', '1'); // $show_attributes = $config->get( 'show_product_attributes', 1); $view->assign('show_tax', $show_tax); $view->assign('params', $config); //$view->assign( 'show_attributes', $show_attributes ); $item->product = $product = self::getItemInfo($product_id); $stock = $product->stock; if (isset($stock->min_sale_qty) && $stock->min_sale_qty > 1) { $item->product_quantity = (int) $stock->min_sale_qty; $item->item_minimum_notice = JText::sprintf('K2STORE_MINIMUM_QUANTITY_NOTIFICATION', $item->title, (int) $stock->min_sale_qty); } else { $item->product_quantity = 1; } //get attributes $attributes = $model->getProductOptions($product_id); if (count($attributes) && $product->stock->manage_stock == 1 && K2STORE_PRO == 1 && !$config->get('allow_backorder', 0)) { //get unavailable attribute options $attributes = $model->processAttributeOptions($attributes, $product); //print_r($attributes ); } $item->attributes = $attributes; //get k2store product item $product = self::getItemInfo($product_id); $stock = K2StoreInventory::getStock($product_id); //quantity //get prices $item->prices = K2StorePrices::getPrice($product_id, $item->product_quantity); //base price $item->price = $item->prices->product_baseprice; //tax $t = new K2StoreTax(); //assign tax class to the view. so that we dont have to call it everytime. $view->assign('tax_class', $t); $tax = $t->getProductTax($item->price, $item->product_id); $item->tax = isset($tax) ? $tax : 0; //special price $item->special_price = isset($item->prices->product_specialprice) ? (double) $item->prices->product_specialprice : null; $sp_tax = $t->getProductTax($item->special_price, $item->product_id); $item->sp_tax = isset($sp_tax) ? $sp_tax : 0; //now get the total stock if (K2STORE_PRO == 1) { JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2store/models'); $qtyModel = JModelLegacy::getInstance('ProductQuantities', 'K2StoreModel'); $qtyModel->setState('filter_product', $item->product_id); $item->product_stock = $qtyModel->getQuantityTotal(); } else { $item->product_stock = ''; } $view->assign('attributes', $attributes); $view->assign('product', $product); $view->assign('params', $config); //trigger onBeforeAddtocart plugin event if (!is_object($item->event)) { $item->event = new stdClass(); } $item->event->K2StoreBeforeCartDisplay = ''; $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('k2store'); $results = $dispatcher->trigger("onK2StoreBeforeCartDisplay", array($item)); $item->event->K2StoreBeforeCartDisplay = trim(implode("\n", $results)); $view->assign('item', $item); ob_start(); $view->display(); $html = ob_get_contents(); ob_end_clean(); return $html; }