Пример #1
0
 public function onBeforeSave(&$model, &$data)
 {
     $utility_helper = J2Store::utilities();
     if (isset($data['cross_sells'])) {
         $data['cross_sells'] = $utility_helper->to_csv($data['cross_sells']);
     } else {
         $data['cross_sells'] = '';
     }
     if (isset($data['up_sells'])) {
         $data['up_sells'] = $utility_helper->to_csv($data['up_sells']);
     } else {
         $data['up_sells'] = '';
     }
     if (isset($data['shippingmethods']) && !empty($data['shippingmethods'])) {
         $data['shippingmethods'] = implode(',', $data['shippingmethods']);
     }
     if (isset($data['item_options']) && count($data['item_options']) > 0) {
         $data['has_options'] = 1;
     }
     //bind existing params
     if ($data['j2store_product_id']) {
         $product = F0FTable::getAnInstance('Product', 'J2StoreTable');
         $product->load($data['j2store_product_id']);
         if ($product->params) {
             $product->params = json_decode($product->params);
             $data['params'] = array_merge((array) $product->params, (array) $data['params']);
         }
     }
     if (isset($data['params']) && !empty($data['params'])) {
         $data['params'] = json_encode($data['params']);
     }
     $this->_rawData = $data;
 }
Пример #2
0
 function read()
 {
     // Makes sure SiteGround's SuperCache doesn't cache the subscription page
     J2Store::utilities()->nocache();
     $app = JFactory::getApplication();
     $app->setHeader('X-Cache-Control', 'False', true);
     $method = $app->input->getCmd('method', 'none');
     $model = $this->getModel('Callback');
     $result = $model->runCallback($method);
     echo $result ? 'OK' : 'FAILED';
     $app->close();
 }
Пример #3
0
 public function onBeforeSave(&$model, &$data)
 {
     $utility_helper = J2Store::utilities();
     if (isset($data['cross_sells'])) {
         $data['cross_sells'] = $utility_helper->to_csv($data['cross_sells']);
     } else {
         $data['cross_sells'] = '';
     }
     if (isset($data['up_sells'])) {
         $data['up_sells'] = $utility_helper->to_csv($data['up_sells']);
     } else {
         $data['up_sells'] = '';
     }
     if (isset($data['shippingmethods']) && !empty($data['shippingmethods'])) {
         $data['shippingmethods'] = implode(',', $data['shippingmethods']);
     }
     if (isset($data['item_options']) && count($data['item_options']) > 0) {
         $data['has_options'] = 1;
     }
     $this->_rawData = $data;
 }
Пример #4
0
<?php

/*------------------------------------------------------------------------
# mod_j2store_cart - J2 Store Cart
# ------------------------------------------------------------------------
# author    Sasi varna kumar - Weblogicx India http://www.weblogicxindia.com
# copyright Copyright (C) 2014 - 19 Weblogicxindia.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://j2store.org
# Technical Support:  Forum - http://j2store.org/forum/index.html
-------------------------------------------------------------------------*/
// no direct access
defined('_JEXEC') or die('Restricted access');
$app = JFactory::getApplication();
require_once JPATH_ADMINISTRATOR . '/components/com_j2store/helpers/j2store.php';
J2Store::utilities()->nocache();
$ajax = $app->getUserState('mod_j2store_mini_cart.isAjax');
$hide = false;
if ($params->get('check_empty', 0) && $list['product_count'] < 1) {
    $hide = true;
}
?>

	<?php 
if (!$ajax) {
    ?>
		<div class="j2store_cart_module_<?php 
    echo $module->id;
    ?>
">
	<?php 
Пример #5
0
 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');
     if (isset($options)) {
         $options = array_filter($options);
     } else {
         $options = array();
     }
     //iterate through stored options for this product and validate
     foreach ($product->product_options as $product_option) {
         //check option type should not be file
         if ($product_option->required && empty($options[$product_option->j2store_productoption_id])) {
             $errors['error']['option'][$product_option->j2store_productoption_id] = JText::sprintf('J2STORE_ADDTOCART_PRODUCT_OPTION_REQUIRED', $product_option->option_name);
         }
         if (!empty($options[$product_option->j2store_productoption_id])) {
             F0FModel::getTmpInstance('Options', 'J2StoreModel')->validateOptionRules($options[$product_option->j2store_productoption_id], $product_option, $errors);
         }
     }
     $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->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;
 }
Пример #6
0
 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;
 }
Пример #7
0
 /**
  * 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;
 }
Пример #8
0
 function update()
 {
     //first clear cache
     J2Store::utilities()->nocache();
     $model = $this->getThisModel();
     $model->getName();
     $json = $model->updateProduct();
     if ($json === false) {
         $json = array();
         $json['errormsg'] = implode('/n', $model->getErrors());
         $json['error'] = 1;
     }
     echo json_encode($json);
     JFactory::getApplication()->close();
 }
Пример #9
0
					<span class="required">*</span>
					<div class="controls">
					<?php 
echo J2Html::select()->clearState()->type('genericlist')->name('country_id')->idTag('country_id')->value($this->params->get('country_id'))->setPlaceHolders(array('' => JText::_('J2STORE_SELECT_OPTION')))->hasOne('Countries')->setRelations(array('fields' => array('key' => 'j2store_country_id', 'name' => 'country_name')))->getHtml();
?>
					</div>
				</div>

				<div class="control-group">
					<?php 
echo J2Html::label(JText::_('J2STORE_STORE_DEFAULT_CURRENCY'), 'config_currency', array('class' => 'control-label'));
?>
					<span class="required">*</span>
					<div class="controls">
					<?php 
$currencies = J2Store::utilities()->world_currencies();
echo J2Html::select()->clearState()->type('genericlist')->name('config_currency')->value($this->params->get('config_currency', 'USD'))->setPlaceHolders($currencies)->getHtml();
?>
					</div>
				</div>

				<div class="control-group">
					<?php 
echo J2Html::label(JText::_('J2STORE_CURRENCY_SYMBOL_LABEL'), 'config_currency_symbol', array('class' => 'control-label'));
?>
					<div class="controls">
					<?php 
echo J2Html::text('config_currency_symbol', '', array('id' => 'config_currency_symbol', 'placeholder' => '$'));
?>
					</div>
				</div>
Пример #10
0
 function formatCustomFields($type, $data_field, &$order)
 {
     $address = F0FTable::getAnInstance('Address', 'J2StoreTable');
     $fields = J2Store::getSelectableBase()->getFields($type, $address, 'address', '', true);
     foreach ($fields as $field) {
         $order[$type . '_' . JString::strtolower($field->field_namekey)] = '';
     }
     $registry = new JRegistry();
     $registry->loadString(stripslashes($data_field), 'JSON');
     $custom_fields = $registry->toObject();
     $row = F0FTable::getAnInstance('Orderinfo', 'J2StoreTable');
     if (isset($custom_fields) && count($custom_fields)) {
         foreach ($custom_fields as $namekey => $field) {
             if (!property_exists($row, $type . '_' . strtolower($namekey)) && !property_exists($row, 'user_' . $namekey) && $namekey != 'country_id' && $namekey != 'zone_id' && $namekey != 'option' && $namekey != 'task' && $namekey != 'view' && $namekey != 'email') {
                 if (is_object($field)) {
                     $string = '';
                     if (is_array($field->value)) {
                         $k = count($field->value);
                         $i = 1;
                         foreach ($field->value as $value) {
                             $string .= JText::_($value);
                             if ($i != $k) {
                                 $string .= '|';
                             }
                             $i++;
                         }
                     } elseif (is_object($field->value)) {
                         //convert the object into an array
                         $obj_array = JArrayHelper::fromObject($field->value);
                         $k = count($obj_array);
                         $i = 1;
                         foreach ($obj_array as $value) {
                             $string .= JText::_($value);
                             if ($i != $k) {
                                 $string .= '|';
                             }
                             $i++;
                         }
                     } elseif (J2Store::utilities()->isJson(stripslashes($field->value))) {
                         $json_values = json_decode(stripslashes($field->value));
                         if (is_array($json_values)) {
                             $k = count($json_values);
                             $i = 1;
                             foreach ($json_values as $value) {
                                 $string .= JText::_($value);
                                 if ($i != $k) {
                                     $string .= '|';
                                 }
                                 $i++;
                             }
                         } else {
                             $string .= JText::_($field->value);
                         }
                     } else {
                         $string = JText::_($field->value);
                     }
                     if (!empty($string)) {
                         $order[$type . '_' . JString::strtolower($namekey)] = $string;
                     }
                 }
             }
         }
     }
 }
Пример #11
0
 public function validateQuantityRestriction($variant, $cart_total_qty, $addto_qty = 0)
 {
     $error = '';
     if ($variant->quantity_restriction && J2Store::isPro()) {
         $quantity_total = $cart_total_qty + $addto_qty;
         $min = $variant->min_sale_qty;
         $max = $variant->max_sale_qty;
         if ($max && $max > 0) {
             if ($quantity_total > $max) {
                 $error = JText::sprintf('J2STORE_MAX_QUANTITY_FOR_PRODUCT', floatval($max), J2Store::utilities()->stock_qty($cart_total_qty));
             }
         }
         if ($min && $min > 0) {
             if ($quantity_total < $min) {
                 $error = JText::sprintf('J2STORE_MIN_QUANTITY_FOR_PRODUCT', floatval($min));
             }
         }
     }
     return $error;
 }
Пример #12
0
 function shippingUpdate()
 {
     //first clear cache
     J2Store::utilities()->nocache();
     J2Store::utilities()->clear_cache();
     $model = $this->getModel('Carts', 'J2StoreModel');
     $app = JFactory::getApplication();
     $session = JFactory::getSession();
     $values = $this->input->getArray($_REQUEST);
     $shipping_values = array();
     $shipping_values['shipping_price'] = isset($values['shipping_price']) ? $values['shipping_price'] : 0;
     $shipping_values['shipping_extra'] = isset($values['shipping_extra']) ? $values['shipping_extra'] : 0;
     $shipping_values['shipping_code'] = isset($values['shipping_code']) ? $values['shipping_code'] : '';
     $shipping_values['shipping_name'] = isset($values['shipping_name']) ? $values['shipping_name'] : '';
     $shipping_values['shipping_tax'] = isset($values['shipping_tax']) ? $values['shipping_tax'] : 0;
     $shipping_values['shipping_plugin'] = isset($values['shipping_plugin']) ? $values['shipping_plugin'] : '';
     $session->set('shipping_values', $shipping_values, 'j2store');
     $redirect = $model->getCartUrl();
     echo json_encode(array('redirect' => $redirect));
     $app->close();
 }
Пример #13
0
 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();
 }
Пример #14
0
 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;
 }
Пример #15
0
 protected function onDisplay($tpl = null)
 {
     $app = JFactory::getApplication();
     $session = JFactory::getSession();
     $view = $this->input->getCmd('view', 'cpanel');
     $params = J2Store::config();
     J2Store::utilities()->nocache();
     $this->currency = J2Store::currency();
     $this->store = J2Store::storeProfile();
     if (in_array($view, array('cpanel', 'cpanels'))) {
         return;
     }
     $country_id = $this->input->getInt('country_id');
     if (isset($country_id)) {
         $session->set('billing_country_id', $country_id, 'j2store');
         $session->set('shipping_country_id', $country_id, 'j2store');
     } elseif ($session->has('shipping_country_id', 'j2store')) {
         $country_id = $session->get('shipping_country_id', '', 'j2store');
     } else {
         $country_id = $this->store->get('country_id');
     }
     $zone_id = $this->input->getInt('zone_id');
     if (isset($zone_id)) {
         $session->set('billing_zone_id', $zone_id, 'j2store');
         $session->set('shipping_zone_id', $zone_id, 'j2store');
     } elseif ($session->has('shipping_zone_id', 'j2store')) {
         $zone_id = $session->get('shipping_zone_id', '', 'j2store');
     } else {
         $zone_id = $this->store->get('zone_id');
     }
     $postcode = $this->input->getString('postcode');
     if (isset($postcode)) {
         $session->set('shipping_postcode', $postcode, 'j2store');
     } elseif ($session->has('shipping_postcode', 'j2store')) {
         $postcode = $session->get('shipping_postcode', '', 'j2store');
     } else {
         $postcode = $this->store->get('zip');
     }
     $this->country_id = $country_id;
     $this->zone_id = $zone_id;
     $this->postcode = $postcode;
     if ($params->get('hide_shipping_untill_address_selection', 1) == 0) {
         $session->set('billing_country_id', $country_id, 'j2store');
         $session->set('shipping_country_id', $country_id, 'j2store');
         $session->set('billing_zone_id', $zone_id, 'j2store');
         $session->set('shipping_zone_id', $zone_id, 'j2store');
         $session->set('shipping_postcode', $postcode, 'j2store');
         $session->set('force_calculate_shipping', 1, 'j2store');
     }
     // Load the model
     $model = $this->getModel();
     $items = $model->getItems();
     //plugin trigger
     $this->before_display_cart = '';
     $before_results = J2Store::plugin()->event('BeforeDisplayCart', array($items));
     foreach ($before_results as $result) {
         $this->before_display_cart .= $result;
     }
     //trigger plugin events
     $i = 0;
     $onDisplayCartItem = array();
     foreach ($items as $item) {
         ob_start();
         J2Store::plugin()->event('DisplayCartItem', array($i, $item));
         $cartItemContents = ob_get_contents();
         ob_end_clean();
         if (!empty($cartItemContents)) {
             $onDisplayCartItem[$i] = $cartItemContents;
         }
         $i++;
     }
     $this->onDisplayCartItem = $onDisplayCartItem;
     $order = F0FModel::getTmpInstance('Orders', 'J2StoreModel')->populateOrder($items)->getOrder();
     $order->validate_order_stock();
     $this->order = $order;
     $this->items = $order->getItems();
     foreach ($this->items as $item) {
         if (isset($item->orderitemattributes) && count($item->orderitemattributes)) {
             foreach ($item->orderitemattributes as &$attribute) {
                 if ($attribute->orderitemattribute_type == 'file') {
                     unset($table);
                     $table = F0FTable::getInstance('Upload', 'J2StoreTable');
                     if ($table->load(array('mangled_name' => $attribute->orderitemattribute_value))) {
                         $attribute->orderitemattribute_value = $table->original_name;
                     }
                 }
             }
         }
     }
     $this->taxes = $order->getOrderTaxrates();
     $this->shipping = $order->getOrderShippingRate();
     $this->coupons = $order->getOrderCoupons();
     $this->vouchers = $order->getOrderVouchers();
     $this->taxModel = F0FModel::getTmpInstance('TaxProfiles', 'J2StoreModel');
     //do we have shipping methods
     $this->shipping_methods = $session->get('shipping_methods', array(), 'j2store');
     $this->shipping_values = $session->get('shipping_values', array(), 'j2store');
     $this->checkout_url = $model->getCheckoutUrl();
     $this->continue_shopping_url = $model->getContinueShoppingUrl();
     $this->after_display_cart = '';
     $results = J2Store::plugin()->event('AfterDisplayCart', array($order));
     foreach ($results as $result) {
         $this->after_display_cart .= $result;
     }
     // Pass page params on frontend only
     if (F0FPlatform::getInstance()->isFrontend()) {
         $this->params = $params;
     }
     return true;
 }
Пример #16
0
"
				   />

	   </div>
	<?php 
} else {
    ?>
			<input value="<?php 
    echo JText::_('J2STORE_OUT_OF_STOCK');
    ?>
" type="button" class="j2store_button_no_stock btn btn-warning" />
	<?php 
}
?>

	<?php 
echo J2Store::plugin()->eventWithHtml('AfterAddToCartButton', array($this->product, J2Store::utilities()->getContext('view_cart')));
?>

	<input type="hidden" name="option" value="com_j2store" />
	<input type="hidden" name="view" value="carts" />
	<input type="hidden" name="task" value="addItem" />
	<input type="hidden" name="ajax" value="0" />
	<?php 
echo JHTML::_('form.token');
?>
	<input type="hidden" name="return" value="<?php 
echo base64_encode(JUri::getInstance()->toString());
?>
" />
	<div class="j2store-notifications"></div>
Пример #17
0
:</dt>
		<dd>
		<?php 
            if (is_array($field->value)) {
                echo '<br />';
                foreach ($field->value as $value) {
                    echo '- ' . JText::_($value) . '<br/>';
                }
            } elseif (is_object($field->value)) {
                //convert the object into an array
                $obj_array = JArrayHelper::fromObject($field->value);
                echo '<br />';
                foreach ($obj_array as $value) {
                    echo '- ' . JText::_($value) . '<br/>';
                }
            } elseif (is_string($field->value) && J2Store::utilities()->isJson(stripslashes($field->value))) {
                $json_values = json_decode(stripslashes($field->value));
                if (is_array($json_values)) {
                    foreach ($json_values as $value) {
                        echo '- ' . JText::_($value) . '<br/>';
                    }
                } else {
                    echo JText::_($field->value);
                }
            } else {
                echo JText::_($field->value);
            }
            ?>
		</dd>
<?php 
        }
Пример #18
0
 /**
  * This method occurs after payment is attempted,
  * and fires the onPostPayment plugin event
  *
  * @return unknown_type
  */
 function confirmPayment()
 {
     J2Store::utilities()->nocache();
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $session = JFactory::getSession();
     $params = J2Store::config();
     $order_model = F0FModel::getTmpInstance('Orders', 'J2StoreModel');
     $orderpayment_type = $app->input->getString('orderpayment_type');
     $view = $this->getThisView();
     if ($model = $this->getThisModel()) {
         // Push the model into the view (as default)
         $view->setModel($model, true);
     }
     // 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 = $session->get('account', 'register', 'j2store');
     // get the order_id from the session set by the prePayment
     $orderpayment_id = (int) $app->getUserState('j2store.orderpayment_id');
     $order_id = $app->getUserState('j2store.order_id');
     //clear
     $app->setUserState('j2store.order_id', null);
     $app->setUserState('j2store.orderpayment_id', null);
     $order = F0FTable::getAnInstance('Order', 'J2StoreTable')->getClone();
     $order->load(array('order_id' => $order_id));
     $clear_cart = $params->get('clear_cart', 'order_placed');
     if ($clear_cart == 'order_placed') {
         $order->empty_cart();
     }
     $order_link = JRoute::_('index.php?option=com_j2store&view=myprofile');
     if ($session->has('guest', 'j2store') && !$user->id) {
         $guest = $session->get('guest', array(), 'j2store');
         $session->set('guest_order_email', $guest['billing']['email'], 'j2store');
         $session->set('guest_order_token', $order->token, 'j2store');
     }
     JPluginHelper::importPlugin('j2store');
     $html = "";
     // free product? set the state to confirmed and save the order.
     if (!empty($order_id) && (double) $order->order_total == (double) '0.00') {
         $order->payment_complete();
     } else {
         $values = array();
         $values['order_id'] = $order_id;
         $values['order_state_id'] = 1;
         // get the payment results from the payment plugin
         $results = $app->triggerEvent("onJ2StorePostPayment", 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('order_id' => $order_id));
     }
     // $order_id would be empty on posts back from Paypal, for example
     if (isset($order->order_id) && !empty($order->order_id)) {
         //fail-safe
         if ($clear_cart == 'order_placed') {
             $order->empty_cart();
         }
         // unset a few things from the session.
         $session->clear('shipping_method', 'j2store');
         $session->clear('shipping_methods', 'j2store');
         $session->clear('payment_method', 'j2store');
         $session->clear('payment_methods', 'j2store');
         $session->clear('payment_values', 'j2store');
         $session->clear('guest', 'j2store');
         $session->clear('customer_note', 'j2store');
         // clear coupon and voucher
         $session->clear('coupon', 'j2store');
         $session->clear('voucher', 'j2store');
         // trigger onAfterOrder plugin event
         $results = $app->triggerEvent("onJ2StoreAfterPayment", array($order));
         foreach ($results as $result) {
             $html .= $result;
         }
     }
     $params = J2Store::config();
     if ($params->get('show_postpayment_orderlink', 1)) {
         $view->assign('order_link', $order_link);
     } else {
         $view->assign('order_link', '');
     }
     if (isset($order)) {
         $view->assign('order', $order);
     }
     $view->assign('plugin_html', $html);
     $view->setLayout('postpayment');
     $view->display();
     return;
 }