function getDataNew() { require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php'; $session = JFactory::getSession(); // Lets load the content if it doesn't already exist if (empty($this->_data) && count($session->get('j2store_cart'))) { foreach ($session->get('j2store_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 = J2StoreHelperCart::getItemInfo($product_id); //now get product options if ($product_info) { $option_price = 0; $option_weight = 0; $option_data = array(); 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') { //ok now get product option values $product_option_value = $this->getCartProductOptionValues($product_option->product_option_id, $option_value); 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; } //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, 'option_sku' => $product_option_value->product_optionvalue_sku, 'weight_prefix' => $product_option_value->product_optionvalue_weight_prefix); } } 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; } //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, 'option_sku' => $product_option_value->product_optionvalue_sku, 'weight_prefix' => $product_option_value->product_optionvalue_weight_prefix); } } } 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' => '', 'weight' => '', 'weight_prefix' => ''); } } } //get the product price //base price $price = $product_info->price; //we may have special price or discounts. so check $price_override = J2StorePrices::getPrice($product_info->product_id, $quantity); if (isset($price_override) && !empty($price_override)) { $price = $price_override->product_price; } $this->_data[$key] = array('key' => $key, 'product_id' => $product_info->product_id, 'name' => $product_info->product_name, 'model' => $product_info->product_sku, 'raw_options' => $options, 'option' => $option_data, 'option_price' => $option_price, 'quantity' => $quantity, 'stock' => $product_info, 'tax_profile_id' => $product_info->tax_profile_id, 'shipping' => $product_info->item_shipping, 'price' => $price + $option_price, 'total' => ($price + $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); } } } return $this->_data; }
private function getProduct($values, $text) { $html = ''; $product_id = $values[0]; $product_enabled = J2StorePrices::getItemEnabled($product_id); if (!$product_enabled) { return $html; } $this->_updateCurrency(); if (in_array('price', $values)) { $prices = J2StorePrices::getPrice($product_id); $html .= '<span class="j2store-product-price">'; $html .= J2StorePrices::number($prices->product_price); $html .= '</span>'; } return $html; }
/** * Method to getItem * @params type int id * @result products */ public function getItem() { $id = $this->getId(); $product = J2StoreHelperCart::getItemInfo($id); //set the correct quantity if (isset($product->min_sale_qty) && $product->min_sale_qty > 1 && J2STORE_PRO == 1) { $product->product_quantity = (int) $product->min_sale_qty; $product->item_minimum_notice = JText::sprintf('J2STORE_MINIMUM_QUANTITY_NOTIFICATION', $product->product_name, (int) $product->min_sale_qty); } else { $product->product_quantity = 1; } //include the model file path JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_j2store/models'); //create obj for cartmodel class $cart_model = JModelLegacy::getInstance('Mycart', 'J2StoreModel'); //now get the productoptions based on the id $attributes = $cart_model->getProductOptions($id); //let calcuate the product option based on the stock if (count($attributes) && $product->manage_stock == 1 && J2STORE_PRO == 1) { //get unavailable attribute options $attributes = $cart_model->processAttributeOptions($attributes, $product); } //assign the attributes $product->attributes = $attributes; //assign th prices $product->prices = J2StorePrices::getPrice($id, $product->product_quantity); if (J2STORE_PRO == 1 && $product->manage_stock == 1) { JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/models'); $qtyModel = JModelLegacy::getInstance('ProductQuantities', 'J2StoreModel'); $qtyModel->setState('filter_product', $product->product_id); $qtyModel->setState('filter_productid', $product->product_id); $product->option_stock = $qtyModel->getList(); $product->product_stock = $qtyModel->getQuantityTotal(); } else { $product->product_stock = 99; } $product->product = $product; $product->inventory = J2StoreInventory::isAllowed($product); //get all tags if (version_compare(JVERSION, '3.0', 'ge')) { $product->product_tags = $this->getProductTags($id); } $this->executePlugins($product); return $product; }
public static function getAjaxCart($item, $values = array()) { $app = JFactory::getApplication(); if (is_array($values) && !count($values)) { $values = $app->input->getArray($_REQUEST); } //load javascript files require_once JPATH_ADMINISTRATOR . '/components/com_j2store/helpers/strapper.php'; J2StoreStrapper::addJS(); J2StoreStrapper::addCSS(); $html = ''; JLoader::register("J2StoreViewMyCart", JPATH_SITE . "/components/com_j2store/views/mycart/view.html.php"); $layout = 'addtocart'; $view = new J2StoreViewMyCart(); $view->addTemplatePath(JPATH_SITE . '/components/com_j2store/views/mycart/tmpl'); $view->addTemplatePath(JPATH_SITE . '/templates/' . $app->getTemplate() . '/html/com_j2store/mycart'); require_once JPATH_SITE . '/components/com_j2store/models/mycart.php'; $model = new J2StoreModelMyCart(); $product_id = $item->product_id = $item->id; $view->assign('_basePath', JPATH_SITE . '/components/com_j2store'); $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_j2store'); $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 ); //get j2store fields $item->product = $product = self::getItemInfo($product_id); $item->attribs = $product->product->attribs; //quantity if (isset($product->min_sale_qty) && $product->min_sale_qty > 1 && J2STORE_PRO == 1) { $item->product_quantity = (int) $product->min_sale_qty; $item->item_minimum_notice = JText::sprintf('J2STORE_MINIMUM_QUANTITY_NOTIFICATION', $product->product_name, (int) $product->min_sale_qty); } else { $item->product_quantity = 1; } //get attributes $attributes = $model->getProductOptions($product_id); if (count($attributes) && $product->manage_stock == 1 && J2STORE_PRO == 1 && !$config->get('allow_backorder', 0)) { //get unavailable attribute options $attributes = $model->processAttributeOptions($attributes, $product); //print_r($attributes ); } //get prices $item->prices = J2StorePrices::getPrice($product_id, $item->product_quantity); //tax $t = new J2StoreTax(); //assign tax class to the view. so that we dont have to call it everytime. $view->assign('tax_class', $t); if (isset($item->prices->product_specialprice) && $item->prices->product_specialprice > 0) { $item->special_price = $item->prices->product_specialprice; } elseif (isset($item->prices->product_customer_groupprice) && $item->prices->product_customer_groupprice >= 0) { $item->special_price = $item->prices->product_customer_groupprice; } else { $item->special_price = null; } $sp_tax = $t->getProductTax($item->special_price, $item->product_id); $item->sp_tax = isset($sp_tax) ? $sp_tax : 0; if ($item->special_price) { //we have an offer $item->price = $item->prices->product_baseprice; } else { $item->price = $item->prices->product_price; } $tax = $t->getProductTax($item->price, $item->product_id); $item->tax = isset($tax) ? $tax : 0; //now get the total stock if (J2STORE_PRO == 1 && $product->manage_stock == 1) { JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/models'); $qtyModel = JModelLegacy::getInstance('ProductQuantities', 'J2StoreModel'); $qtyModel->setState('filter_product', $item->product_id); if ($config->get('show_option_stock', 0)) { $qtyModel->setState('filter_productid', $item->product_id); $item->option_stock = $qtyModel->getList(); } $item->product_stock = $qtyModel->getQuantityTotal(); } else { $item->product_stock = ''; } //item sku $item->product_sku = $product->item_sku; $view->assign('product', $product); $view->assign('attributes', $attributes); $view->assign('params', $config); $view->assign('item', $item); ob_start(); $view->display(); $html = ob_get_contents(); ob_end_clean(); return $html; }