protected function onBeforeStore($updateNulls = false) { if (!isset($this->sku) || empty($this->sku)) { //sku is empty. Auto generate it based on product name $product_helper = J2Store::product(); $this->sku = $product_helper->generateSKU($this); } return parent::onBeforeStore($updateNulls); }
public function browse() { $app = JFactory::getApplication(); $model = $this->getThisModel(); $state = $this->getFilterStates(); foreach ($state as $key => $value) { $model->setState($key, $value); } //$product_types = $model->getProductTypes(); //array_unshift($product_types, JText::_('J2STORE_SELECT_OPTION')); $products = $model->getStockProductList(); $product_helper = J2Store::product(); foreach ($products as $product) { $product->product = $product_helper->setId($product->j2store_product_id)->getProduct(); } $view = $this->getThisView(); $view->setModel($model); $view->assign('products', $products); $view->assign('state', $model->getState()); //$view->assign('product_types',$product_types); return parent::browse(); }
function setpaimport() { $app = JFactory::getApplication(); $model = $this->getThisModel(); $view = $this->getThisView(); $view->setModel($model, true); $product_id = $app->input->getInt('product_id', 0); if ($product_id) { $product_type = $app->input->getString('product_type', 'simple'); $model->setState('product_type', $product_type); $product_list = $model->getProductList(); $products = array(); foreach ($product_list as $item) { // run the getItem again unset($product); if (isset($item->has_options) && $item->has_options) { $product = F0FModel::getTmpInstance('Products', 'J2StoreModel')->runMyBehaviorFlag(true)->getItem($item->j2store_product_id); $products[] = $product; } } $items = F0FModel::getTmpInstance('Productoptions', 'J2StoreModel')->getList(); $total = F0FModel::getTmpInstance('Productoptions', 'J2StoreModel')->getTotal(); $pagination = F0FModel::getTmpInstance('Productoptions', 'J2StoreModel')->getPagination(); $view->assign('model', $model); $view->assign('state', $model->getState()); $view->assign('products', $products); $row = F0FModel::getTmpInstance('Products', 'J2StoreModel')->getItem($product_id); $view->assign('row', $row); $view->assign('productHelper', J2Store::product()); $view->assign('currency', J2Store::currency()); //$view->assign('lists',$lists); $view->assign('total', $total); $view->assign('product_id', $product_id); } $view->setLayout('paimport'); $view->display(); }
public function setItems($cartitems) { $product_helper = J2Store::product(); $productitems = array(); foreach ($cartitems as $cartitem) { if ($cartitem->product_qty == 0) { F0FModel::getTmpInstance('Cartitems', 'J2StoreModel')->setIds(array($cartitem->j2store_cartitem_id))->delete(); continue; } if ($product_helper->managing_stock($cartitem) && $product_helper->backorders_allowed($cartitem) === false) { //this could be wrong. we are not checking the total quantity for product types other than variant type /* if ($cartitem->product_qty > $cartitem->available_quantity && $cartitem->available_quantity >= 1) { JFactory::getApplication ()->enqueueMessage ( JText::sprintf ( "J2STORE_CART_QUANTITY_ADJUSTED", $cartitem->product_name, $cartitem->product_qty, $cartitem->available_quantity ) ); $cartitem->product_qty = $cartitem->available_quantity; } */ // removing the product from the cart if it's not available if ($cartitem->available_quantity == 0) { F0FModel::getTmpInstance('Cartitems', 'J2StoreModel')->setIds(array($cartitem->j2store_cartitem_id))->delete(); continue; } } unset($orderItem); // TODO Push this into the orders object->addItem() method? $orderItem = $this->getTable()->getClone(); $orderItem->cart_id = $cartitem->cart_id; $orderItem->cartitem_id = $cartitem->j2store_cartitem_id; $orderItem->product_id = $cartitem->product_id; $orderItem->product_source = $cartitem->product_source; $orderItem->product_source_id = $cartitem->product_source_id; $orderItem->product_type = $cartitem->product_type; $orderItem->product_params = $cartitem->product_params; $orderItem->variant_id = $cartitem->variant_id; $orderItem->orderitem_sku = $cartitem->sku; $orderItem->vendor_id = $cartitem->vendor_id; $orderItem->orderitem_name = $cartitem->product_name; $orderItem->orderitem_quantity = J2Store::utilities()->stock_qty($cartitem->product_qty); //set the entire cartitem. We can use it later $orderItem->cartitem = $cartitem; // price which is not processed $orderItem->orderitem_price = $cartitem->pricing->price; $orderItem->orderitem_baseprice = $cartitem->pricing->base_price; $orderItem->orderitem_option_price = $cartitem->option_price; // the following four includes the option prices as well // $orderItem->orderitem_price_with_tax = $cartitem->pricing->price_with_tax; // $orderItem->orderitem_price_without_tax = $cartitem->pricing->price_without_tax; // $orderItem->orderitem_baseprice_with_tax = $cartitem->pricing->base_price_with_tax; // $orderItem->orderitem_baseprice_without_tax = $cartitem->pricing->base_price_without_tax; $orderItem->orderitem_taxprofile_id = $cartitem->taxprofile_id; $orderItem->orderitem_weight = $cartitem->weight; $orderItem->orderitem_weight_total = $cartitem->weight_total; //just a placeholder and also used as reference for product options $orderItem->orderitem_attributes = $cartitem->product_options; $orderItem->orderitem_raw_attributes = $cartitem->product_options; //prepare options $this->getOrderItemOptions($orderItem, $cartitem); //prepare orderitem_params and add some data that might be useful $this->getOrderItemParams($orderItem, $cartitem); JPluginHelper::importPlugin('j2store'); $results = JFactory::getApplication()->triggerEvent("onJ2StoreAfterAddCartItemToOrder", array($cartitem)); foreach ($results as $result) { foreach ($result as $key => $value) { $orderItem->set($key, $value); } } J2Store::plugin()->event('AfterAddOrderItem', array(&$orderItem)); // TODO When do attributes for selected item get set during admin-side order creation? array_push($this->_items, $orderItem); } return $this; }
<?php /** * @package J2Store * @copyright Copyright (c)2014-17 Ramesh Elamathi / J2Store.org * @license GNU GPL v3 or later */ // No direct access defined('_JEXEC') or die; $options = $this->product->options; $product_id = $this->product->j2store_product_id; $product_helper = J2Store::product(); if ($options) { ?> <div class="options"> <?php foreach ($options as $option) { ?> <?php echo J2Store::plugin()->eventWithHtml('BeforeDisplaySingleProductOption', array($this->product, $option)); ?> <?php //var_dump($option); ?> <?php if ($option['type'] == 'select') { ?> <!-- select -->
public function view() { $product_id = $this->input->getInt('id'); if (!$product_id) { $this->setRedirect(JRoute::_('index.php')); return; } //first clear cache J2Store::utilities()->nocache(); J2Store::utilities()->clear_cache(); $app = JFactory::getApplication(); $view = $this->getThisView(); if ($model = $this->getThisModel()) { // Push the model into the view (as default) $view->setModel($model, true); } $ns = 'com_j2store.' . $this->getName(); $params = F0FModel::getTmpInstance('Products', 'J2StoreModel')->getMergedParams(); if ($params->get('item_show_vote', 0)) { $params->set('show_vote', 1); } $product_helper = J2Store::product(); //get product $product = $product_helper->setId($product_id)->getProduct(); F0FModel::getTmpInstance('Products', 'J2StoreModel')->runMyBehaviorFlag(true)->getProduct($product); if ($product->visibility != 1 || $product->enabled != 1) { $this->setRedirect(JRoute::_('index.php'), JText::_('J2STORE_PRODUCT_NOT_ENABLED_CONTACT_SITE_ADMIN_FOR_MORE_DETAILS'), 'warning'); return; } //run plugin events $model->executePlugins($product->source, $params, 'com_content.article.productlist'); $product->product_short_desc = $model->runPrepareEventOnDescription($product->product_short_desc, $product->product_source_id, $params, 'com_content.article.productlist'); $product->product_long_desc = $model->runPrepareEventOnDescription($product->product_long_desc, $product->product_source_id, $params, 'com_content.article.productlist'); //get filters / specs by product $filters = F0FModel::getTmpInstance('Products', 'J2StoreModel')->getProductFilters($product->j2store_product_id); //upsells $up_sells = array(); if ($params->get('item_show_product_upsells', 0) && !empty($product->up_sells)) { $up_sells = $product_helper->getUpsells($product); } //cross sells $cross_sells = array(); if ($params->get('item_show_product_cross_sells', 0) && !empty($product->cross_sells)) { $cross_sells = $product_helper->getCrossSells($product); } if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } // Look for template files in component folders $view->addTemplatePath(JPATH_SITE . '/components/com_j2store/templates'); $view->addTemplatePath(JPATH_SITE . '/components/com_j2store/templates/default'); // Look for overrides in template folder (J2 template structure) $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . 'templates'); $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . 'templates' . DS . 'default'); // Look for overrides in template folder (Joomla! template structure) $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . 'default'); $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store'); // Look for specific J2 theme files if ($params->get('subtemplate')) { $view->addTemplatePath(JPATH_COMPONENT . DS . 'templates' . DS . $params->get('subtemplate')); $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . 'templates' . DS . $params->get('subtemplate')); $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_j2store' . DS . $params->get('subtemplate')); } //set up document // Check for layout override only if this is not the active menu item // If it is the active menu item, then the view and category id will match $active = $app->getMenu()->getActive(); $menus = $app->getMenu(); $pathway = $app->getPathway(); $document = JFactory::getDocument(); // Because the application sets a default page title, // we need to get it from the menu item itself $menu = $menus->getActive(); $params->def('page_heading', $product->product_name); $params->set('page_title', $product->product_name); $title = $params->get('page_title', ''); // Check for empty title and add site name if param is set if (empty($title)) { $title = $app->get('sitename'); } elseif ($app->get('sitename_pagetitles', 0) == 1) { $title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $title); } elseif ($app->get('sitename_pagetitles', 0) == 2) { $title = JText::sprintf('JPAGETITLE', $title, $app->get('sitename')); } $document->setTitle($title); if ($product->source->metadesc) { $document->setDescription($product->source->metadesc); } else { $metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $product->source->introtext . ' ' . $product->source->fulltext); $metaDescItem = strip_tags($metaDescItem); $metaDescItem = J2Store::utilities()->characterLimit($metaDescItem, 150); $document->setDescription(html_entity_decode($metaDescItem)); } if ($product->source->metakey) { $document->setMetadata('keywords', $product->source->metakey); } else { $keywords = $params->get('menu-meta_keywords'); $document->setMetaData('keywords', $keywords); } $metadata = json_decode($product->source->metadata); if (isset($metadata->robots)) { $document->setMetaData('robots', $metadata->robots); } else { $robots = $params->get('robots'); $document->setMetaData('robots', $robots); } // Set Facebook meta data $uri = JURI::getInstance(); $document->setMetaData('og:title', $document->getTitle()); $document->setMetaData('og:site_name', $app->get('sitename')); $document->setMetaData('og:description', strip_tags($document->getDescription())); $document->setMetaData('og:url', $uri->toString()); $document->setMetaData('og:type', 'product'); if (isset($product->main_image)) { $facebookImage = $product->main_image; } else { $facebookImage = $product->thumb_image; } if (!empty($facebookImage)) { if (JFile::exists(JPATH_SITE . '/' . $facebookImage)) { $image = substr(JURI::root(), 0, -1) . '/' . str_replace(JURI::root(true), '', $facebookImage); $document->setMetaData('og:image', $image); $document->setMetaData('image', $image); } } //set canonical url foreach ($document->_links as $key => $value) { if (is_array($value)) { if (array_key_exists('relation', $value)) { if ($value['relation'] == 'canonical') { // we found the document link that contains the canonical url // change it! $canonicalUrl = $uri->toString(); $document->_links[$canonicalUrl] = $value; unset($document->_links[$key]); break; } } } } $back_link = $app->getMenu()->getActive()->link; $back_link_title = $app->getMenu()->getActive()->title; if (isset($back_link) && !empty($back_link_title)) { $view->assign('back_link', JRoute::_($back_link)); $view->assign('back_link_title', $back_link_title); } //add a pathway $pathway = $app->getPathway(); $path = array(array('title' => $product->product_name, 'link' => '')); if (isset($product->source->category_title)) { $path[] = array('title' => $product->source->category_title, 'link' => ''); //JRoute::_('index.php?option=com_j2store&view=products&Itemid='.$app->getMenu()->getActive()->id) } $path = array_reverse($path); foreach ($path as $item) { $pathway->addItem($item['title'], $item['link']); } //add custom styles $custom_css = $params->get('custom_css', ''); $document->addStyleDeclaration(strip_tags($custom_css)); //allow plugins to modify the data J2Store::plugin()->event('ViewProduct', array(&$product, &$view)); $view->assign('product', $product); $view->assign('filters', $filters); $view->assign('up_sells', $up_sells); $view->assign('cross_sells', $cross_sells); $view->assign('product_helper', $product_helper); $view->assign('params', $params); $view->assign('currency', J2store::currency()); $view->setLayout('view'); $view->display(); }
if (isset($this->product->source->event->beforeDisplayContent)) { ?> <?php echo $this->product->source->event->beforeDisplayContent; ?> <?php } ?> <?php echo $this->loadTemplate('sku'); ?> <?php echo $this->loadTemplate('brand'); ?> <?php if ($this->params->get('item_show_product_stock', 1) && J2Store::product()->managing_stock($this->product->variant)) { ?> <?php echo $this->loadTemplate('stock'); ?> <?php } ?> </div> </div> <?php if ($this->params->get('catalog_mode', 0) == 0) { ?> <form action="<?php
public function onUpdateProduct(&$model, &$product) { $app = JFactory::getApplication(); $product_helper = J2Store::product(); $params = J2Store::config(); //first get the correct variant $options = $app->input->get('product_option', array(0), 'ARRAY'); if (isset($options)) { $options = array_filter($options); } else { $options = array(); } //no options found. so just return an empty array if (count($options) < 1) { return false; } //options found. Get the correct variant $variant = $product_helper->getVariantByOptions($options, $product->j2store_product_id); if ($variant === false) { return false; } //now we have the variant. Process. //get quantity restrictions $product_helper->getQuantityRestriction($variant); $quantity = $app->input->getFloat('product_qty', 1); if ($variant->quantity_restriction && $variant->min_sale_qty > 0) { $quantity = $variant->min_sale_qty > $quantity ? $variant->min_sale_qty : $quantity; } //check stock status if ($product_helper->check_stock_status($variant, $quantity)) { //reset the availability $variant->availability = 1; } else { $variant->availability = 0; } //process pricing. returns an object $variant->pricing = $product_helper->getPrice($variant, $quantity); //prepare return values $return = array(); $return['variant_id'] = $variant->j2store_variant_id; $return['sku'] = $variant->sku; $return['quantity'] = floatval($quantity); $return['price'] = $variant->price; $return['availability'] = $variant->availability; $return['manage_stock'] = $variant->manage_stock; $return['allow_backorder'] = $variant->allow_backorder; if ($variant->availability) { $return['stock_status'] = J2Store::product()->displayStock($variant, $params); } else { $return['stock_status'] = JText::_('J2STORE_OUT_OF_STOCK'); } $return['pricing'] = array(); $return['pricing']['base_price'] = J2Store::product()->displayPrice($variant->pricing->base_price, $product, $params); $return['pricing']['price'] = J2Store::product()->displayPrice($variant->pricing->price, $product, $params); //dimensions $return['dimensions'] = round($variant->length, 2) . ' x ' . round($variant->height, 2) . ' x ' . round($variant->width, 2) . ' ' . $variant->length_title; $return['weight'] = round($variant->weight, 2) . ' ' . $variant->weight_title; return $return; }
?> <?php if ($option_value['product_optionvalue_price'] > 0 && $this->params->get('product_option_price', 1)) { ?> ( <?php if ($this->params->get('product_option_price_prefix', 1)) { ?> <?php echo $option_value['product_optionvalue_prefix']; ?> <?php } ?> <?php echo J2Store::product()->displayPrice($option_value['product_optionvalue_price'], $this->product, $this->params); ?> ) <?php } ?> </label> <br /> <?php } ?> </div> <br /> <script type="text/javascript">
} ?> <?php } ?> <?php if ($list['product_count'] > 0) { ?> <?php foreach ($advanced_list as $item) { $registry = new JRegistry(); $registry->loadString($item->orderitem_params); $item->params = $registry; $thumb_image = $item->params->get('thumb_image', ''); $product = J2Store::product()->setId($item->product_id)->getProduct(); ?> <li class="cartitems"> <div class="item-info"> <?php if ($params->get('show_thumbimage') && !empty($thumb_image)) { ?> <span class="cart-thumb-image"> <img alt="<?php echo $item->orderitem_name; ?> " src="<?php echo JUri::root(true) . '/' . $thumb_image; ?> " />
echo J2Html::label(JText::_('J2STORE_PRODUCT_SET_ADVANCED_PRICING'), 'sale_price', array('class' => 'control-label')); ?> <?php $url = "index.php?option=com_j2store&view=products&task=setproductprice&variant_id=" . $this->variant->j2store_variant_id . "&layout=productpricing&tmpl=component"; ?> <?php echo J2StorePopup::popup($url, JText::_("J2STORE_PRODUCT_SET_PRICES"), array('class' => 'btn btn-success btn-small')); ?> </div> <div class="control-group"> <?php echo J2Html::label(JText::_('J2STORE_PRODUCT_PRICING_CALCULATOR'), 'pricing_calculator', array('class' => 'control-label input-small')); ?> <?php //pricing options echo J2Html::select()->clearState()->type('genericlist')->name($prefix . '[pricing_calculator]')->value($this->variant->pricing_calculator)->attribs(array('id' => 'pricing_calculator_' . $this->variant->j2store_variant_id, 'class' => 'input-small'))->setPlaceHolders(J2Store::product()->getPricingCalculators())->getHtml(); ?> </div> </div> <div class="span6"> <div class="control-group"> <?php echo J2Html::label(JText::_('J2STORE_PRODUCT_ENABLE_SHIPPING'), 'shipping', array('class' => 'control-label')); ?> <?php // echo J2Html::radio($prefix.'[shipping]', $this->variant->shipping,array('class'=>'controls' ,'id'=> 'shipping-'.$this->variant->j2store_variant_id)); ?> <?php //pricing options
<?php //$relatedModel = F0FModel::getAnInstance('Products', 'J2StoreModel')->getClone(); //$related_product = $relatedModel->getItem($value); $product = J2Store::product(); $related_product = $product->product_id($value)->getProduct(); ?> <?php if (isset($related_product->product_source_id)) { ?> <tr id="crossSell-<?php echo $value; ?> "> <td class="addedProductCrosssell"> <?php $related_product = J2Store::product()->clearState()->product_id($value)->getProduct(); ?> <a href="index.php?option=com_content&task=article.edit&id=<?php echo $related_product->product_source_id; ?> " target="_blank"> <?php echo $related_product->product_name; ?> </a> <input type="hidden" value="<?php echo $value; ?> " name="<?php echo $this->form_prefix . '[cross_sells]'; ?>
/** * Method to validate stock in an order. Called only before placing the order. * @return boolean True if successful | False if a condition does not match */ public function validate_order_stock() { $product_helper = J2Store::product(); $utilities = J2Store::utilities(); $items = $this->getItems(); if (count($items) < 1) { return true; } $quantity_in_cart = $this->get_orderitem_stock($items); foreach ($items as $item) { // check quantity restrictions if ($item->cartitem->quantity_restriction && J2Store::isPro()) { // get quantity restriction $product_helper->getQuantityRestriction($item->cartitem); $quantity = $quantity_in_cart[$item->variant_id]; $min = $item->cartitem->min_sale_qty; $max = $item->cartitem->max_sale_qty; if ($max && $max > 0) { if ($quantity > $max) { JFactory::getApplication()->enqueueMessage(JText::sprintf("J2STORE_CART_ITEM_MAXIMUM_QUANTITY_REACHED", $item->orderitem_name, $utilities->stock_qty($max), $utilities->stock_qty($quantity))); return false; } } if ($min && $min > 0) { if ($quantity < $min) { JFactory::getApplication()->enqueueMessage(JText::sprintf("J2STORE_CART_ITEM_MINIMUM_QUANTITY_REQUIRED", $item->orderitem_name, $utilities->stock_qty($min), $utilities->stock_qty($quantity))); return false; } } } if ($product_helper->managing_stock($item->cartitem) && $product_helper->backorders_allowed($item->cartitem) == false) { $productQuantity = F0FTable::getInstance('ProductQuantity', 'J2StoreTable')->getClone(); $productQuantity->load(array('variant_id' => $item->variant_id)); // no stock, right now? if ($productQuantity->quantity < 1) { JFactory::getApplication()->enqueueMessage(JText::sprintf("J2STORE_CART_ITEM_STOCK_NOT_AVAILABLE", $item->orderitem_name)); return false; } // not enough stock ? if ($productQuantity->quantity > 0 && $quantity_in_cart[$item->variant_id] > $productQuantity->quantity) { JFactory::getApplication()->enqueueMessage(JText::sprintf("J2STORE_CART_ITEM_STOCK_NOT_ENOUGH_STOCK", $item->orderitem_name, $utilities->stock_qty($productQuantity->quantity))); return false; } } } return true; }
public function get_discount_amount($discounting_amount, $cartitem, $order, $single = true) { $discount = 0; $app = JFactory::getApplication(); $params = J2Store::config(); $session = JFactory::getSession(); $sub_total = $order->subtotal; if ($this->coupon->value_type == 'F') { $this->coupon->value = min($this->coupon->value, $sub_total); } if ($this->coupon->value_type == 'F') { //TODO: Not sure this is correct. We have to apply the right discount value. $discount_percent = 0; if ($order->subtotal_ex_tax) { $product_helper = J2Store::product(); $actual_price = $cartitem->orderitem_price + $cartitem->orderitem_option_price; $price_for_discount = $product_helper->get_price_excluding_tax($actual_price * $cartitem->orderitem_quantity, $cartitem->orderitem_taxprofile_id); $discount_percent = $price_for_discount / $order->subtotal_ex_tax; $discount = min($this->coupon->value * $discount_percent / $cartitem->orderitem_quantity, $discounting_amount); } //$discount = $this->coupon->value * ($discounting_amount / $sub_total); } elseif ($this->coupon->value_type == 'P') { $discount = $discounting_amount / 100 * $this->coupon->value; } //has free shipping if ($this->coupon->free_shipping) { $order->allow_free_shipping(); } //allow plugins to modify the amount J2Store::plugin()->event('GetCouponDiscountAmount', array($discount, $discounting_amount, $cartitem, $order, $this, $single)); return $discount; }
?> )" href="javascript:void(0);" > <i class="icon icon-trash"></i> </a> </div> #<?php echo $this->variant->j2store_variant_id; ?> -- <a data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $this->variant->j2store_variant_id; ?> "> <?php echo J2Store::product()->getVariantNamesByCSV($this->variant->variant_name); ?> <i id="icon-downarrow-<?php echo $this->variant->j2store_variant_id; ?> " class="icon-arrow-down" onclick="jQuery('#icon-uparrow-<?php echo $this->variant->j2store_variant_id; ?> ').toggle('click');jQuery('#icon-downarrow-<?php echo $this->variant->j2store_variant_id; ?> ').toggle('click');" data-toggle-tag="icon-uparrow-<?php
function validate_item(&$cartitem) { $product_helper = J2Store::product(); if (!$product_helper->setId($cartitem->product_id)->exists()) { $this->setIds(array($cartitem->j2store_cartitem_id))->delete(); JFactory::getApplication()->enqueueMessage(JText::_('J2STORE_CART_ITEM_UNAVAILABLE_REMOVED'), 'warning'); unset($cartitem); } }
public function get_discount_amount($price, $cartitem, $order, $single = true) { $voucher_history_total = $this->get_voucher_history($this->voucher->j2store_voucher_id); if ($voucher_history_total) { $amount = $this->voucher->voucher_value - $voucher_history_total; } else { $amount = $this->voucher->voucher_value; } /** * This is the most complex discount - we need to divide the discount between rows based on their price in * proportion to the subtotal. This is so rows with different tax rates get a fair discount, and so rows * with no price (free) don't get discounted. * * Get item discount by dividing item cost by subtotal to get a % */ $params = J2Store::config(); $product_helper = J2Store::product(); $cart_item_qty = $cartitem->orderitem_quantity; $discount_percent = 0; if ($params->get('config_including_tax', 0)) { $actual_price = $cartitem->orderitem_price + $cartitem->orderitem_option_price; $price_for_discount = $product_helper->get_price_including_tax($actual_price * $cart_item_qty, $cartitem->orderitem_taxprofile_id); $discount_percent = $price_for_discount / $order->subtotal; } else { $actual_price = $cartitem->orderitem_price + $cartitem->orderitem_option_price; $price_for_discount = $product_helper->get_price_excluding_tax($actual_price * $cart_item_qty, $cartitem->orderitem_taxprofile_id); $discount_percent = $price_for_discount / $order->subtotal_ex_tax; } $discount = $amount * $discount_percent / $cart_item_qty; //allow plugins to modify the discount J2Store::plugin()->event('GetVoucherDiscountAmount', array($discount, $price, $cartitem, $order, $this, $single)); return $discount; }
/** * Method to get Cross sell products * @param object $source_product Source Product Table Object * @return array An array of products or an empty array if no results found. */ public function getCrossSells($source_product) { $cross_sell_csv = $source_product->cross_sells; $products = array(); $cross_sells = array(); if (!empty($cross_sell_csv)) { $item_cross_sells = explode(',', $cross_sell_csv); if (count($item_cross_sells)) { $cross_sells = array_merge($item_cross_sells, $cross_sells); } if (count($cross_sells)) { foreach ($cross_sells as $cross_sell) { $cross_sell_product = $this->setId($cross_sell)->getProduct(); if (empty($cross_sell_product->product_name)) { continue; } F0FModel::getTmpInstance('Products', 'J2StoreModel')->runMyBehaviorFlag(true)->getProduct($cross_sell_product); if ($cross_sell_product->variant->availability || J2Store::product()->backorders_allowed($cross_sell_product->variant)) { $show = true; } else { $show = false; } if ($cross_sell_product->product_type == 'variable') { $show = true; } // Dont show if product not available. No use in showing a related product that is not available! if ($show == false) { continue; } $products[] = $cross_sell_product; } } } // allow plugins to modify the results J2Store::plugin()->event('AfterGetCrossSells', array(&$products, $source_product)); return $products; }
public function send_stock_notifications($variant, $new_stock, $qty_ordered) { $app = JFactory::getApplication(); // Backorders if ($new_stock < 0) { J2Store::plugin()->event('ProductOnBackorder', array($variant, $this->order_id, $qty_ordered)); } // stock status notifications $notification_sent = false; if ($new_stock <= 0) { J2Store::plugin()->event('NotifyNoStock', array($variant)); $notification_sent = true; } J2Store::product()->getQuantityRestriction($variant); if (!$notification_sent && $variant->notify_qty >= $new_stock) { J2Store::plugin()->event('NotifyLowStock', array($variant, $new_stock)); $notification_sent = true; } }
/** * Method to update product information * * @return array or false */ public function updateProduct() { $result = array(); $product_id = $this->input->getInt('product_id', 0); if (!$product_id) { return false; } $product = J2Store::product()->setId($product_id)->getProduct(); if ($product->product_type) { $this->addBehavior($product->product_type); } else { $this->addBehavior('simple'); } try { // Call the behaviors $data = $this->modelDispatcher->trigger('onUpdateProduct', array(&$this, &$product)); if (count($data)) { $result = $data[0]; } } catch (Exception $e) { // Oops, an exception occured! $this->setError($e->getMessage()); return false; } //plugin trigger $result['afterDisplayPrice'] = J2Store::plugin()->eventWithHtml('AfterUpdateProduct', array($data)); return $result; }
function update() { $app = JFactory::getApplication(); $post = $app->input->getArray($_POST); $productHelper = J2Store::product(); $cart_id = $this->getCartId(); $json = array(); foreach ($post['quantities'] as $cartitem_id => $quantity) { $cartitem = F0FModel::getTmpInstance('Cartitem', 'J2StoreModel')->getItem($cartitem_id); //sanity check if ($cartitem->cart_id != $cart_id) { continue; } // get the difference quantity if ($this->validate($cartitem, $quantity) === false) { // an error occured. Return it $json['error'] = $this->getError(); continue; // exit from the loop } // validation successful. Update cart $cartitem2 = F0FTable::getInstance('Cartitem', 'J2StoreTable'); $cartitem2->load($cartitem_id); if (empty($quantity) || $quantity < 1) { // the user wants to remove the item from cart. so remove it $item = new JObject(); $item->product_id = $cartitem->product_id; $item->variant_id = $cartitem->variant_id; $item->product_type = $cartitem->product_type; $item->product_options = $cartitem->product_options; $cartitem2->delete($cartitem_id); J2Store::plugin()->event('RemoveFromCart', array($item)); } else { $cartitem2->product_qty = J2Store::utilities()->stock_qty($quantity); $cartitem2->store(); } } J2Store::plugin()->event('AfterUpdateCart', array($cart_id, $post)); return $json; }
<?php /** * @package J2Store * @copyright Copyright (c)2014-17 Ramesh Elamathi / J2Store.org * @license GNU GPL v3 or later */ // No direct access defined('_JEXEC') or die; if (!empty($this->product->addtocart_text)) { $cart_text = JText::_($this->product->addtocart_text); } else { $cart_text = JText::_('J2STORE_ADD_TO_CART'); } if ($this->product->variant->availability || J2Store::product()->backorders_allowed($this->product->variant)) { $show = true; } else { $show = false; } if ($this->product->product_type == 'variable') { $show = true; } echo J2Store::plugin()->eventWithHtml('BeforeAddToCartButton', array($this->product, J2Store::utilities()->getContext('view_cart'))); ?> <?php if ($show) { ?> <div class="cart-action-complete" style="display:none;"> <p class="text-success"> <?php echo JText::_('J2STORE_ITEM_ADDED_TO_CART');
// No direct access defined('_JEXEC') or die; $this->form_id = 'j2store-addtocart-form-' . $this->product->j2store_product_id; ?> <?php echo $this->loadTemplate('sku'); ?> <?php echo $this->loadTemplate('price'); ?> <?php if (J2Store::product()->managing_stock($this->product->variant)) { ?> <?php echo $this->loadTemplate('stock'); ?> <?php } if ($this->params->get('catalog_mode', 0) == 0) { ?> <form action="<?php echo $this->product->cart_form_action; ?> " method="post" class="j2store-addtocart-form" id="<?php echo $this->form_id;
public function onUpdateProduct(&$model, &$product) { $app = JFactory::getApplication(); $params = J2Store::config(); $product_helper = J2Store::product(); $product_id = $app->input->getInt('product_id', 0); if (!$product_id) { return false; } // get variant $variants = F0FModel::getTmpInstance('Variants', 'J2StoreModel')->product_id($product->j2store_product_id)->is_master(1)->getList(); $product->variants = $variants[0]; // process variant $product->variant = $product->variants; // get quantity restrictions $product_helper->getQuantityRestriction($product->variant); // now process the quantity $product->quantity = $app->input->getFloat('product_qty', 1); if ($product->variant->quantity_restriction && $product->variant->min_sale_qty > 0) { $product->quantity = $product->variant->min_sale_qty; } // process pricing. returns an object $pricing = $product_helper->getPrice($product->variant, $product->quantity); $selected_product_options = $app->input->get('product_option', array(), 'ARRAY'); // get the selected option price if (count($selected_product_options)) { $product_option_data = $product_helper->getOptionPrice($selected_product_options, $product->j2store_product_id); $base_price = $pricing->base_price + $product_option_data['option_price']; $price = $pricing->price + $product_option_data['option_price']; } else { $base_price = $pricing->base_price; $price = $pricing->price; } $return = array(); $return['pricing'] = array(); $return['pricing']['base_price'] = $product_helper->displayPrice($base_price, $product, $params); $return['pricing']['price'] = $product_helper->displayPrice($price, $product, $params); return $return; }
public function onValidateCart(&$model, $cartitem, $quantity) { //sanity check if ($cartitem->product_type != 'simple') { return; } $product_helper = J2Store::product(); $product = $product_helper->setId($cartitem->product_id)->getProduct(); $variant = F0FModel::getTmpInstance('Variants', 'J2StoreModel')->getItem($cartitem->variant_id); $errors = array(); //before validating, get the total quantity of this variant in the cart $cart_total_qty = $product_helper->getTotalCartQuantity($variant->j2store_variant_id); //get the quantity difference. Because we are going to check the total quantity $difference_qty = $quantity - $cartitem->product_qty; //validate minimum / maximum quantity $error = $product_helper->validateQuantityRestriction($variant, $cart_total_qty, $difference_qty); if (!empty($error)) { $errors[] = $error; } //validate inventory if ($product_helper->check_stock_status($variant, $cart_total_qty + $difference_qty) === false) { $errors[] = JText::_('J2STORE_OUT_OF_STOCK'); } if (count($errors)) { throw new Exception(implode('/n', $errors)); return false; } return true; }
<?php /** * @package J2Store * @copyright Copyright (c)2014-17 Ramesh Elamathi / J2Store.org * @license GNU GPL v3 or later */ // No direct access defined('_JEXEC') or die; //pricing options $pricing_calculator = J2Html::select()->clearState()->type('genericlist')->name($this->form_prefix . '[pricing_calculator]')->value($this->variant->pricing_calculator)->setPlaceHolders(J2Store::product()->getPricingCalculators())->getHtml(); ?> <div class="j2store-product-pricing"> <div class="control-group"> <?php echo J2Html::label(JText::_('J2STORE_PRODUCT_REGULAR_PRICE'), 'price', array('class' => 'control-label')); ?> <?php echo J2Html::price($this->form_prefix . '[price]', $this->variant->price, array('class' => 'input')); ?> </div> <div class="control-group"> <?php echo J2Html::label(JText::_('J2STORE_PRODUCT_SET_ADVANCED_PRICING'), 'sale_price', array('class' => 'control-label')); ?> <!-- Link to advanced pricing options. Opens as a popup. --> <?php echo J2StorePopup::popup("index.php?option=com_j2store&view=products&task=setproductprice&variant_id=" . $this->variant->j2store_variant_id . "&layout=productpricing&tmpl=component", JText::_("J2STORE_PRODUCT_SET_PRICES"), array('class' => 'btn btn-success')); ?> </div>
<div class="sale-price"> <?php echo $sale_price; ?> </div> <?php } ?> <?php if ($this->params->get('display_price_with_tax_info', 0)) { ?> <div class="tax-text"> <?php echo J2Store::product()->get_tax_text(); ?> </div> <?php } ?> <meta itemprop="price" content="<?php echo $this->product->pricing->price; ?> " /> <meta itemprop="priceCurrency" content="<?php echo $this->currency->getCode(); ?> " />
?> <?php echo J2Html::select()->clearState()->type('genericlist')->name($this->prefix . '[' . $poptionvalue->j2store_product_optionvalue_id . '][parent_optionvalue][]')->value($poptionvalue->parent_optionvalue)->setPlaceHolders($parent_option_array)->attribs(array('multiple' => true))->getHtml(); ?> </td> <?php } ?> <?php if ($this->product_option->is_variant != 1) { ?> <td> <?php echo J2Store::product()->getPriceModifierHtml($this->prefix . '[' . $poptionvalue->j2store_product_optionvalue_id . '][product_optionvalue_prefix]', $poptionvalue->product_optionvalue_prefix); ?> </td> <td> <?php echo J2Html::text($this->prefix . '[' . $poptionvalue->j2store_product_optionvalue_id . '][product_optionvalue_price]', $poptionvalue->product_optionvalue_price, array('id' => 'product_optionvalue_price', 'class' => 'input-small')); ?> </td> <td> <?php echo J2Html::select()->clearState()->type('genericlist')->name($this->prefix . '[' . $poptionvalue->j2store_product_optionvalue_id . '][product_optionvalue_weight_prefix]')->value($poptionvalue->product_optionvalue_weight_prefix)->setPlaceHolders(array('+' => '+', '-' => '-'))->attribs(array('class' => 'input-small'))->getHtml(); ?> </td> <td>
public function get_product_cross_sells_html() { $html = ''; if (empty($this->j2store_product_id)) { return $html; } //ok. We have a product. $view = $this->get_view(); $product_helper = J2Store::product(); $cross_sells = $product_helper->getCrossSells($this); $model = F0FModel::getTmpInstance('Products', 'J2StoreModel'); $view->setModel($model, true); $model->setState('task', 'read'); J2StoreStrapper::addJS(); J2StoreStrapper::addCSS(); $params = J2Store::config(); $view->assign('cross_sells', $cross_sells); $view->assign('params', $params); $view->setLayout('item_crosssells'); ob_start(); $view->display(); $html = ob_get_contents(); ob_end_clean(); $html .= J2Store::plugin()->eventWithHtml('AfterRenderingProductCrossSells', array($this, $cross_sells)); return $html; }
public function onBeforeAddCartItem(&$model, $product, &$json) { $app = JFactory::getApplication(); $product_helper = J2Store::product(); $values = $app->input->getArray($_REQUEST); $errors = array(); //run quantity check $quantity = $app->input->get('product_qty'); if (isset($quantity)) { $quantity = $quantity; } else { $quantity = 1; } //get options //get the product options $options = $app->input->get('product_option', array(0), 'ARRAY'); $check_option = $options; if (isset($options)) { $options = array_filter($options); } else { $options = array(); } $reloaded_product_options = F0FModel::getTmpInstance('ProductOptions', 'J2StoreModel')->product_id($product->j2store_product_id)->parent_id(null)->getList(); unset($product->product_options); $product->product_options = $reloaded_product_options; $product_options = $product_helper->getProductOptions($product); $ommit_check = array(); //iterate through stored options for this product and validate foreach ($product_options as $product_option) { $check_require = F0FModel::getTmpInstance('ProductOptions', 'J2StoreModel')->getItem($product_option['productoption_id']); if ($check_require->required && empty($check_option[$product_option['productoption_id']]) && $check_require->parent_id == 0 || in_array($product_option['productoption_id'], $ommit_check)) { $errors['error']['option'][$product_option['productoption_id']] = JText::sprintf('J2STORE_ADDTOCART_PRODUCT_OPTION_REQUIRED', $product_option['option_name']); } else { if (array_key_exists($product_option['productoption_id'], $options)) { if (is_array($options[$product_option['productoption_id']])) { foreach ($options[$product_option['productoption_id']] as $optionvalue) { $child = $product_helper->getChildProductOptions($product->j2store_product_id, $check_require->option_id, $optionvalue); if (!empty($child)) { foreach ($child as $index => $attr) { if (count($attr['optionvalue']) > 0 && $attr['required'] && !array_key_exists($attr['productoption_id'], $options)) { array_push($ommit_check, $attr['productoption_id']); } } } } } else { $child = $product_helper->getChildProductOptions($product->j2store_product_id, $check_require->option_id, $options[$product_option['productoption_id']]); if (!empty($child)) { foreach ($child as $index => $attr) { if (count($attr['optionvalue']) > 0 && $attr['required'] && !array_key_exists($attr['productoption_id'], $options)) { array_push($ommit_check, $attr['productoption_id']); } } } } } } } $cart = $model->getCart(); if (!$errors && $cart->cart_type != 'wishlist') { //before validating, get the total quantity of this variant in the cart $cart_total_qty = $product_helper->getTotalCartQuantity($product->variants->j2store_variant_id); //validate minimum / maximum quantity $error = $product_helper->validateQuantityRestriction($product->variants, $cart_total_qty, $quantity); if (!empty($error)) { $errors['error']['stock'] = $error; } //validate inventory if ($product_helper->check_stock_status($product->variants, $cart_total_qty + $quantity) === false) { $errors['error']['stock'] = JText::_('J2STORE_OUT_OF_STOCK'); } } if (!$errors) { //all good. Add the product to cart // create cart object out of item properties $item = new JObject(); $item->user_id = JFactory::getUser()->id; $item->product_id = (int) $product->j2store_product_id; $item->variant_id = (int) $product->variants->j2store_variant_id; $item->product_qty = J2Store::utilities()->stock_qty($quantity); $item->product_options = base64_encode(serialize($options)); $item->product_type = $product->product_type; $item->vendor_id = isset($product->vendor_id) ? $product->vendor_id : '0'; // onAfterCreateItemForAddToCart: plugin can add values to the item before it is being validated /added // once the extra field(s) have been set, they will get automatically saved $results = J2Store::plugin()->event("AfterCreateItemForAddToCart", array($item, $values)); foreach ($results as $result) { foreach ($result as $key => $value) { $item->set($key, $value); } } // no matter what, fire this validation plugin event for plugins that extend the checkout workflow $results = array(); $results = J2Store::plugin()->event("BeforeAddToCart", array($item, $values, $product, $product_options)); foreach ($results as $result) { if (!empty($result['error'])) { $errors['error']['general'] = $result['error']; } } // when there is some error from the plugin then the cart item should not be added if (!$errors) { //add item to cart $cartTable = $model->addItem($item); if ($cartTable === false) { //adding to cart is failed $errors['success'] = 0; } else { //adding cart is successful $errors['success'] = 1; $errors['cart_id'] = $cartTable->j2store_cart_id; } } } $json->result = $errors; }