Beispiel #1
0
 /**
  *
  * @return unknown_type
  */
 function getItems()
 {
     // Check the registry to see if our Tienda class has been overridden
     if (!class_exists('Tienda')) {
         JLoader::register("Tienda", JPATH_ADMINISTRATOR . "/components/com_tienda/defines.php");
     }
     // load the config class
     Tienda::load('Tienda', 'defines');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     // get the model
     Tienda::load('TiendaModelCategories', 'models.categories');
     $model = new TiendaModelCategories(array());
     // $model = JModel::getInstance( 'Categories', 'TiendaModel' ); doesnt work sometimes without no apparent reason
     // TODO Make this depend on the current filter_category?
     // setting the model's state tells it what items to return
     $model->setState('filter_enabled', '1');
     $model->setState('order', 'tbl.lft');
     // set the states based on the parameters
     // using the set filters, get a list
     $items = $model->getList();
     if (!empty($items)) {
         foreach ($items as $item) {
             Tienda::load('TiendaHelperRoute', 'helpers.route');
             $item->itemid = TiendaHelperRoute::category($item->category_id, true);
             if (empty($item->itemid)) {
                 $item->itemid = $this->params->get('itemid');
             }
         }
     }
     return $items;
 }
Beispiel #2
0
 /**
  * Displays the Tienda add to cart button
  * 
  * @param $row
  * @param $user
  * @return unknown_type
  */
 function displayCartButton($row, $user)
 {
     $params = new DSCParameter(trim($row->params));
     $product_id = $params->get('tienda_product_id');
     JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
     $model = JModel::getInstance('Products', 'TiendaModel');
     $model->setId($product_id);
     $product = $model->getItem();
     if (!empty($product_id) && !empty($product->product_id)) {
         Tienda::load('TiendaHelperProduct', 'helpers.product');
         if ($this->params->get('redirect_to_tienda') == '1') {
             Tienda::load("TiendaHelperRoute", 'helpers.route');
             $router = new TiendaHelperRoute();
             $link = $router->product($eventproduct->product_id);
             $redirect = JRoute::_($link, false);
             $app = JFactory::getApplication();
             $app->redirect($redirect);
             return;
         }
         // set the redirect
         if ($this->params->get('redirect_back_to_ambrasubs') == '1') {
             $uri = JURI::getInstance();
             $redirect = $uri->toString();
             $return = '';
         } else {
             Tienda::load("TiendaHelperRoute", 'helpers.route');
             $router = new TiendaHelperRoute();
             $itemid = $router->findItemid(array('view' => 'checkout'));
             $redirect = JRoute::_("index.php?option=com_tienda&view=carts&Itemid=" . $itemid, false);
             $uri = JURI::getInstance();
             $return = $uri->toString();
         }
         $vars->redirect = $redirect;
         $vars->return = $return;
         $vars->ambrasubs_type = $row;
         $vars->product = $product;
         echo $this->_getLayout('product_buy', $vars, $this->_element, 'ambrasubs');
     }
 }
 function getObjectInfo($id, $language = null)
 {
     $db = JFactory::getDBO();
     $query = "SELECT a.product_id as id, a.product_name as title" . "\n , c.category_id" . "\n FROM #__tienda_products AS a" . "\n LEFT JOIN #__tienda_productcategoryxref AS b ON b.product_id = a.product_id" . "\n LEFT JOIN #__tienda_categories AS c ON b.category_id = c.category_id" . "\n WHERE a.product_id = " . intval($id);
     $db->setQuery($query, 0, 1);
     $product = $db->loadObject();
     $info = new JCommentsObjectInfo();
     if (!empty($product)) {
         $routerHelper = JPATH_ROOT . '/administrator/components/com_tienda/helpers/route.php';
         if (is_file($routerHelper)) {
             require_once $routerHelper;
             $info->title = $product->title;
             $info->access = 0;
             $info->userid = 0;
             $info->link = JRoute::_(TiendaHelperRoute::product($id, $product->category_id));
         }
     }
     return $info;
 }
Beispiel #4
0
<?php

defined('_JEXEC') or die('Restricted access');
JHTML::_('stylesheet', 'menu.css', 'media/com_tienda/css/');
JHTML::_('script', 'tienda.js', 'media/com_tienda/js/');
JHTML::_('script', 'joomla.javascript.js', 'includes/js/');
Tienda::load('TiendaGrid', 'library.grid');
$items = @$this->items;
$state = @$this->state;
Tienda::load("TiendaHelperRoute", 'helpers.route');
$router = new TiendaHelperRoute();
Tienda::load('TiendaHelperProduct', 'helpers.product');
$menu = TiendaMenu::getInstance(@$this->submenu);
$products_model = $this->getModel('products');
?>

<script type="text/javascript">
tiendaJQ(document).ready(function(){
	DisplaySharingOptions( <?php 
echo $this->row->privacy;
?>
, 0 );

    tiendaJQ('.privatize-wishlist').on('change', function(){
        el = tiendaJQ(this);
        privacy = el.val();
        if (privacy > 0) {
            Tienda.privatizeWishlist(<?php 
echo $this->row->wishlist_id;
?>
, privacy, function(response){
Beispiel #5
0
 /**
  *
  * @return unknown_type
  */
 function update()
 {
     $model = $this->getModel(strtolower(TiendaHelperCarts::getSuffix()));
     $this->_setModelState();
     $user = JFactory::getUser();
     $session = JFactory::getSession();
     $cids = JRequest::getVar('cid', array(0), '', 'ARRAY');
     $product_attributes = JRequest::getVar('product_attributes', array(0), '', 'ARRAY');
     $quantities = JRequest::getVar('quantities', array(0), '', 'ARRAY');
     $post = JRequest::get('post');
     $msg = JText::_('COM_TIENDA_QUANTITIES_UPDATED');
     $remove = JRequest::getVar('remove');
     if ($remove) {
         foreach ($cids as $cart_id => $product_id) {
             //            	$keynames = explode('.', $key);
             //            	$attributekey = $keynames[0].'.'.$keynames[1];
             //            	$index = $keynames[2];
             $row = $model->getTable();
             //main cartitem keys
             $ids = array('user_id' => $user->id, 'cart_id' => $cart_id);
             // fire plugin event: onGetAdditionalCartKeyValues
             //this event allows plugins to extend the multiple-column primary key of the carts table
             $additionalKeyValues = TiendaHelperCarts::getAdditionalKeyValues(null, $post, $index);
             if (!empty($additionalKeyValues)) {
                 $ids = array_merge($ids, $additionalKeyValues);
             }
             if (empty($user->id)) {
                 $ids['session_id'] = $session->getId();
             }
             if ($return = $row->delete(array('cart_id' => $cart_id))) {
                 $item = new JObject();
                 $item->product_id = $product_id;
                 $item->product_attributes = $product_attributes[$cart_id];
                 $item->vendor_id = '0';
                 // vendors only in enterprise version
                 // fire plugin event
                 $dispatcher = JDispatcher::getInstance();
                 $dispatcher->trigger('onRemoveFromCart', array($item));
             }
         }
     } else {
         foreach ($quantities as $cart_id => $value) {
             $carts = JTable::getInstance('Carts', 'TiendaTable');
             $carts->load(array('cart_id' => $cart_id));
             $product_id = $carts->product_id;
             $value = (int) $value;
             //            	$keynames = explode('.', $key);
             //            	$product_id = $keynames[0];
             //            	$attributekey = $product_id.'.'.$keynames[1];
             //            	$index = $keynames[2];
             $vals = array();
             $vals['user_id'] = $user->id;
             $vals['session_id'] = $session->getId();
             $vals['product_id'] = $product_id;
             // fire plugin event: onGetAdditionalCartKeyValues
             //this event allows plugins to extend the multiple-column primary key of the carts table
             //		        	$additionalKeyValues = TiendaHelperCarts::getAdditionalKeyValues( null, $post, $index );
             //		        	if (!empty($additionalKeyValues))
             //		        	{
             //		        		$vals = array_merge($vals, $additionalKeyValues);
             //		        	}
             // using a helper file,To determine the product's information related to inventory
             $availableQuantity = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getAvailableQuantity($product_id, $product_attributes[$cart_id]);
             if ($availableQuantity->product_check_inventory && $value > $availableQuantity->quantity) {
                 JFactory::getApplication()->enqueueMessage(JText::sprintf("COM_TIENDA_NOT_AVAILABLE_QUANTITY", $availableQuantity->product_name, $value));
                 continue;
             }
             if ($value > 1) {
                 $product = JTable::getInstance('Products', 'TiendaTable');
                 $product->load(array('product_id' => $product_id));
                 if ($product->quantity_restriction) {
                     $min = $product->quantity_min;
                     $max = $product->quantity_max;
                     if ($max) {
                         if ($value > $max) {
                             $msg = JText::_('COM_TIENDA_REACHED_MAXIMUM_QUANTITY_FOR_THIS_OBJECT') . $max;
                             $value = $max;
                         }
                     }
                     if ($min) {
                         if ($value < $min) {
                             $msg = JText::_('COM_TIENDA_REACHED_MAXIMUM_QUANTITY_FOR_THIS_OBJECT') . $min;
                             $value = $min;
                         }
                     }
                 }
                 if ($product->product_recurs) {
                     $value = 1;
                 }
             }
             $row = $model->getTable();
             $vals['product_attributes'] = $product_attributes[$cart_id];
             $vals['product_qty'] = $value;
             if (empty($vals['product_qty']) || $vals['product_qty'] < 1) {
                 // remove it
                 if ($return = $row->delete($cart_id)) {
                     $item = new JObject();
                     $item->product_id = $product_id;
                     $item->product_attributes = $product_attributes[$cart_id];
                     $item->vendor_id = '0';
                     // vendors only in enterprise version
                     // fire plugin event
                     $dispatcher = JDispatcher::getInstance();
                     $dispatcher->trigger('onRemoveFromCart', array($item));
                 }
             } else {
                 $row->load($cart_id);
                 $row->product_qty = $vals['product_qty'];
                 $row->save();
             }
         }
     }
     $carthelper = new TiendaHelperCarts();
     $carthelper->fixQuantities();
     if (empty($user->id)) {
         $carthelper->checkIntegrity($session->getId(), 'session_id');
     } else {
         $carthelper->checkIntegrity($user->id);
     }
     Tienda::load("TiendaHelperRoute", 'helpers.route');
     $router = new TiendaHelperRoute();
     $redirect = JRoute::_("index.php?option=com_tienda&view=carts&Itemid=" . $router->findItemid(array('view' => 'carts')), false);
     $this->setRedirect($redirect, $msg);
 }
Beispiel #6
0
/**
 * Parse the url segments
 * Is just a wrapper for TiendaHelperRoute::parse()
 * 
 * @param unknown_type $segments
 * @return unknown_type
 */
function TiendaParseRoute($segments)
{
    return TiendaHelperRoute::parse($segments);
}
Beispiel #7
0
 /**
  * Generates the xml for the update request
  * @param unknown_type $product
  * @param string $etag - etag of the product
  */
 protected function getUpdateXML($product, $etag)
 {
     // perform the insertion
     Tienda::load('TiendaArrayToXML', 'library.xml');
     // Populate the xml request
     $xml = array();
     $xml['app:control']['sc:required_destination']['attributes']['dest'] = 'ProductSearch';
     // Title, id and description
     $xml['title'] = $product->product_name;
     $xml['content']['attributes']['type'] = 'text/html';
     $xml['content'] = $product->product_description;
     $xml['sc:id'] = $product->product_id;
     // Link to the product
     Tienda::load('TiendaHelperRoute', 'helpers.route');
     $xml['link']['attributes']['rel'] = 'alternate';
     $xml['link']['attributes']['type'] = 'text/html';
     $baseurl = str_replace("/administrator/", "/", JURI::base());
     $xml['link']['attributes']['href'] = $baseurl . TiendaHelperRoute::product($product->product_id);
     //$xml['link']['attributes']['href'] = 'http://www.weble.it/products/'.$product->product_id;
     // Condition
     $xml['scp:condition'] = 'new';
     // Price
     $currency_id = Tienda::getInstance()->get('default_currencyid', '1');
     Tienda::load('TiendaTableCurrencies', 'tables.currencies');
     $currency = JTable::getInstance('Currencies', 'TiendaTable');
     $currency->load((int) $currency_id);
     $xml['scp:price']['attributes']['unit'] = trim(strtoupper($currency->currency_code));
     $xml['scp:price']['@value'] = TiendaHelperBase::number(TiendaHelperProduct::getPrice($product->product_id)->product_price, array('num_decimals', '0'));
     // Manufacturer
     Tienda::load('TiendaTableManufacturers', 'tables.manufacturers');
     $manufacturer = JTable::getInstance('Manufacturers', 'TiendaTable');
     if ($manufacturer->load($product->manufacturer_id)) {
         $xml['scp:brand'] = $manufacturer->manufacturer_name;
     }
     $xml['entry']['attributes']['gd:etag'] = $etag;
     // Create the request
     $null = null;
     $helper = new TiendaArrayToXML();
     $ns = array(array('name' => 'app', 'url' => "http://www.w3.org/2007/app"), array('name' => 'gd', 'url' => "http://schemas.google.com/g/2005"), array('name' => 'sc', 'url' => "http://schemas.google.com/structuredcontent/2009"), array('name' => 'scp', 'url' => "http://schemas.google.com/structuredcontent/2009/products"));
     $xml = $helper->toXml($xml, 'entry', $null, $ns, "http://www.w3.org/2005/Atom");
     return $xml;
 }
Beispiel #8
0
 public function getItemid($id, $fallback = null, $allow_null = false)
 {
     Tienda::load('TiendaHelperRoute', 'helpers.route');
     $return = TiendaHelperRoute::findItemid(array('view' => 'products', 'task' => 'view', 'id' => $id));
     if (!$return) {
         $return = TiendaHelperRoute::findItemid(array('view' => 'products', 'task' => 'view'));
         if (!$return) {
             $return = TiendaHelperRoute::findItemid(array('view' => 'products'));
             if (!$return) {
                 if ($fallback) {
                     $return = $fallback;
                 }
                 if (!$allow_null) {
                     if ($categories = $this->getCategories($id)) {
                         $count = count($categories);
                         $cat_model = Tienda::getClass('TiendaModelCategories', 'models.categories');
                         for ($i = 0; !$return && $i < $count; $i++) {
                             $category = $categories[$i];
                             if ($cat_itemid = $cat_model->getItemid($category->category_id, null, true)) {
                                 $return = $cat_itemid;
                             }
                         }
                     }
                     if (!$return) {
                         $return = JRequest::getInt('Itemid');
                     }
                     if (!$return) {
                         $menu = JFactory::getApplication()->getMenu();
                         if ($default = $menu->getDefault() && !empty($default->id)) {
                             $return = $default->id;
                         }
                     }
                 }
             }
         }
     }
     return $return;
 }
Beispiel #9
0
 /**
  * Verifies the fields in a submitted form.
  * Then adds the item to the users cart
  *
  * @return unknown_type
  */
 function addChildrenToCart()
 {
     JRequest::checkToken() or jexit('Invalid Token');
     $product_id = JRequest::getInt('product_id');
     $quantities = JRequest::getVar('quantities', array(0), 'request', 'array');
     $filter_category = JRequest::getInt('filter_category');
     Tienda::load("TiendaHelperRoute", 'helpers.route');
     $router = new TiendaHelperRoute();
     if (!($itemid = $router->product($product_id, $filter_category, true))) {
         $itemid = $router->category(1, true);
     }
     // set the default redirect URL
     $redirect = "index.php?option=com_tienda&view=products&task=view&id={$product_id}&filter_category={$filter_category}&Itemid=" . $itemid;
     $redirect = JRoute::_($redirect, false);
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $helper = TiendaHelperBase::getInstance();
     if (!Tienda::getInstance()->get('shop_enabled', '1')) {
         $this->messagetype = 'notice';
         $this->message = JText::_('COM_TIENDA_SHOP_DISABLED');
         $this->setRedirect($redirect, $this->message, $this->messagetype);
         return;
     }
     $items = array();
     // this will collect the items to add to the cart
     // convert elements to array that can be binded
     $values = JRequest::get('post');
     $attributes_csv = '';
     $user = JFactory::getUser();
     $cart_id = $user->id;
     $id_type = "user_id";
     if (empty($user->id)) {
         $session = JFactory::getSession();
         $cart_id = $session->getId();
         $id_type = "session";
     }
     Tienda::load('TiendaHelperCarts', 'helpers.carts');
     $carthelper = new TiendaHelperCarts();
     $cart_recurs = $carthelper->hasRecurringItem($cart_id, $id_type);
     // TODO get the children
     // loop thru each child,
     // get the list
     JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
     $model = JModel::getInstance('ProductRelations', 'TiendaModel');
     $model->setState('filter_product', $product_id);
     $model->setState('filter_relation', 'parent');
     if ($children = $model->getList()) {
         foreach ($children as $child) {
             $product_qty = $quantities[$child->product_id_to];
             // Integrity checks on quantity being added
             if ($product_qty < 0) {
                 $product_qty = '1';
             }
             // using a helper file to determine the product's information related to inventory
             $availableQuantity = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getAvailableQuantity($child->product_id_to, $attributes_csv);
             if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) {
                 $this->messagetype = 'notice';
                 $this->message = JText::_(JText::sprintf("COM_TIENDA_NOT_AVAILABLE_QUANTITY", $availableQuantity->product_name, $product_qty));
                 $this->setRedirect($redirect, $this->message, $this->messagetype);
                 return;
             }
             // do the item's charges recur? does the cart already have a subscription in it?  if so, fail with notice
             $product = JTable::getInstance('Products', 'TiendaTable');
             $product->load(array('product_id' => $child->product_id_to));
             // if product notforsale, fail
             if ($product->product_notforsale) {
                 $this->messagetype = 'notice';
                 $this->message = JText::_('COM_TIENDA_PRODUCT_NOT_FOR_SALE');
                 $this->setRedirect($redirect, $this->message, $this->messagetype);
                 return;
             }
             if ($product->product_recurs && $cart_recurs) {
                 $this->messagetype = 'notice';
                 $this->message = JText::_('COM_TIENDA_CART_ALREADY_RECURS');
                 $this->setRedirect($redirect, $this->message, $this->messagetype);
                 return;
             }
             if ($product->product_recurs) {
                 $product_qty = '1';
             }
             // create cart object out of item properties
             $item = new JObject();
             $item->user_id = JFactory::getUser()->id;
             $item->product_id = (int) $child->product_id_to;
             $item->product_qty = (int) $product_qty;
             $item->product_attributes = $attributes_csv;
             $item->vendor_id = '0';
             // vendors only in enterprise version
             // does the user/cart match all dependencies?
             $canAddToCart = $carthelper->canAddItem($item, $cart_id, $id_type);
             if (!$canAddToCart) {
                 $this->messagetype = 'notice';
                 $this->message = JText::_('COM_TIENDA_CANNOT_ADD_ITEM_TO_CART') . " - " . $carthelper->getError();
                 $this->setRedirect($redirect, $this->message, $this->messagetype);
                 return;
             }
             // no matter what, fire this validation plugin event for plugins that extend the checkout workflow
             $results = array();
             $dispatcher = JDispatcher::getInstance();
             $results = $dispatcher->trigger("onBeforeAddToCart", array($item, $values));
             for ($i = 0; $i < count($results); $i++) {
                 $result = $results[$i];
                 if (!empty($result->error)) {
                     $this->messagetype = 'notice';
                     $this->message = $result->message;
                     $this->setRedirect($redirect, $this->message, $this->messagetype);
                     return;
                 }
             }
             // if here, add to cart
             $items[] = $item;
         }
     }
     if (!empty($items)) {
         Tienda::load('TiendaHelperCarts', 'helpers.carts');
         foreach ($items as $item) {
             // add the item to the cart
             $cart_helper = new TiendaHelperCarts();
             $cartitem = $cart_helper->addItem($item);
             // fire plugin event
             $dispatcher = JDispatcher::getInstance();
             $dispatcher->trigger('onAfterAddToCart', array($cartitem, $values));
         }
         $this->messagetype = 'message';
         $this->message = JText::_('COM_TIENDA_ITEMS_ADDED_TO_YOUR_CART');
     }
     // After login, session_id is changed by Joomla, so store this for reference
     $session = JFactory::getSession();
     $session->set('old_sessionid', $session->getId());
     // get the 'success' redirect url
     // TODO Enable redirect via base64_encoded urls?
     switch (Tienda::getInstance()->get('addtocartaction', 'redirect')) {
         case "redirect":
             $returnUrl = base64_encode($redirect);
             $itemid = $router->findItemid(array('view' => 'checkout'));
             $redirect = JRoute::_("index.php?option=com_tienda&view=carts&Itemid=" . $itemid, false);
             if (strpos($redirect, '?') === false) {
                 $redirect .= "?return=" . $returnUrl;
             } else {
                 $redirect .= "&return=" . $returnUrl;
             }
             break;
         case "0":
         case "none":
             break;
         case "lightbox":
         default:
             // TODO Figure out how to get the lightbox to display even after a redirect
             break;
     }
     $this->setRedirect($redirect, $this->message, $this->messagetype);
     return;
 }
Beispiel #10
0
 public function addToWishlist()
 {
     $values = array();
     $response = new stdClass();
     $response->html = '';
     $response->error = false;
     Tienda::load("TiendaHelperRoute", 'helpers.route');
     $router = new TiendaHelperRoute();
     // verify form submitted by user
     JRequest::checkToken('get') or jexit('Invalid Token');
     $values['product_id'] = JRequest::getInt('pid');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $product = JTable::getInstance('Products', 'TiendaTable');
     $product->load($values['product_id'], true, false);
     if (empty($product->product_id)) {
         $msg = JText::_('COM_TIENDA_INVALID_PRODUCT');
         $redirect = JRoute::_("index.php?option=com_tienda&view=carts&Itemid=" . $router->findItemid(array('view' => 'carts')), false);
         $this->setRedirect($redirect, $msg, 'error');
         return;
     }
     $values['product_attributes'] = JRequest::getVar('pa', '');
     // use the wishlist model to add the item to the wishlist, let the model handle all logic
     $session = JFactory::getSession();
     $session_id = $session->getId();
     $session->set('old_sessionid', $session_id);
     $user_id = JFactory::getUser()->id;
     $values['user_id'] = $user_id;
     $values['session_id'] = $session_id;
     $model = $this->getModel('wishlists');
     $msg = '';
     $redirect = JRoute::_("index.php?option=com_tienda&view=carts&Itemid=" . $router->findItemid(array('view' => 'carts')), false);
     $type = 'message';
     if (!$model->addItem($values)) {
         $type = 'error';
         $msg = JText::_('COM_TIENDA_COULD_NOT_ADD_TO_WISHLIST');
     } else {
         $url = "index.php?option=com_tienda&view=wishlists&Itemid=" . $router->findItemid(array('view' => 'wishlists'));
         $msg = JText::sprintf('COM_TIENDA_ADDED_TO_WISHLIST', JRoute::_($url));
     }
     $this->setRedirect($redirect, $msg, $type);
     return;
 }
Beispiel #11
0
 public function getItemid($id, $fallback = null, $allow_null = false)
 {
     Tienda::load('TiendaHelperRoute', 'helpers.route');
     $return = TiendaHelperRoute::findItemid(array('view' => 'products', 'task' => '', 'filter_category' => $id));
     if (!$return) {
         $return = TiendaHelperRoute::findItemid(array('view' => 'products', 'task' => ''));
         if (!$return) {
             if ($fallback) {
                 $return = $fallback;
             }
             if (!$allow_null) {
                 if (!$return) {
                     $return = JRequest::getInt('Itemid');
                 }
                 if (!$return) {
                     $menu = JFactory::getApplication()->getMenu();
                     if ($default = $menu->getDefault() && !empty($default->id)) {
                         $return = $default->id;
                     }
                 }
             }
         }
     }
     return $return;
 }
Beispiel #12
0
 /**
  * (non-PHPdoc)
  *
  * @see tienda/site/TiendaController#view()
  */
 function display($cachable = false, $urlparams = false)
 {
     $user = $this->user;
     JRequest::setVar('view', $this->get('suffix'));
     //check if we have one page checkout
     if ($this->onepage_checkout) {
         if (!$user->id) {
             $session = JFactory::getSession();
             $session->set('old_sessionid', $session->getId());
         }
         // Display the onepage checkout view
         $opc_layout = $this->defines->get('one_page_checkout_layout', 'onepage-opc');
         JRequest::setVar('layout', $opc_layout);
         $view = $this->getView($this->get('suffix'), 'html');
         $order = $this->_order;
         $order = $this->populateOrder();
         //get order summarry
         $html = $this->getOrderSummary();
         $view->assign('orderSummary', $html);
         $view->assign('order', $order);
         $view->setTask(true);
         $view->assign('user', $user);
         if (!$user->id) {
             $view->form_user_register = $this->getAdditionalInfoUser();
         }
         //get addresses
         JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
         $model = JModel::getInstance('addresses', 'TiendaModel');
         $model->setState("filter_userid", $this->user->id);
         $model->setState("filter_deleted", 0);
         $addresses = $model->getList();
         // Checking whether shipping is required
         $showShipping = false;
         $cartsModel = $this->getModel('carts');
         if ($isShippingEnabled = $cartsModel->getShippingIsEnabled()) {
             $showShipping = true;
         }
         $billingAddress = $order->getBillingAddress();
         $billing_address_form = $this->getAddressForm($this->billing_input_prefix, !$user->id);
         $view->assign('billing_address_form', $billing_address_form);
         $view->assign('showShipping', $showShipping);
         $view->assign('billing_address', $billingAddress);
         if ($showShipping) {
             $shippingAddress = $order->getShippingAddress();
             $shipping_address_form = $this->getAddressForm($this->shipping_input_prefix, !$user->id, true);
             $view->assign('shipping_address', $shippingAddress);
             $view->assign('shipping_address_form', $shipping_address_form);
         }
         Tienda::load('TiendaHelperPlugin', 'helpers.plugin');
         $dispatcher = JDispatcher::getInstance();
         if ($showShipping) {
             $rates = $this->getShippingRates();
             $default_rate = array();
             if (count($rates) == 1) {
                 $default_rate = $rates[0];
             }
             $shipping_layout = "shipping_yes";
             if (empty($shippingAddress)) {
                 $shipping_layout = "shipping_calculate";
             }
             $shipping_method_form = $this->getShippingHtml($shipping_layout);
             $view->assign('showShipping', $showShipping);
             $view->assign('shipping_method_form', $shipping_method_form);
             $view->assign('rates', $rates);
         }
         $view->assign('payment_options_html', $this->getPaymentOptionsHtml());
         $view->assign('order', $order);
         // are there any enabled coupons?
         $coupons_present = false;
         $model = JModel::getInstance('Coupons', 'TiendaModel');
         $model->setState('filter_enabled', '1');
         if ($coupons = $model->getList()) {
             $coupons_present = true;
         }
         $view->assign('coupons_present', $coupons_present);
         // assign userinfo for credits
         $userinfo = JTable::getInstance('UserInfo', 'TiendaTable');
         $userinfo->load(array('user_id' => $this->user->id));
         $userinfo->credits_total = (double) $userinfo->credits_total;
         $view->assign('userinfo', $userinfo);
         $view->assign('addresses', $addresses);
         $dispatcher = JDispatcher::getInstance();
         ob_start();
         $dispatcher->trigger('onBeforeDisplaySelectPayment', array($order));
         $view->assign('onBeforeDisplaySelectPayment', ob_get_contents());
         ob_end_clean();
         ob_start();
         $dispatcher->trigger('onAfterDisplaySelectPayment', array($order));
         $view->assign('onAfterDisplaySelectPayment', ob_get_contents());
         ob_end_clean();
     } else {
         $guest_var = JRequest::getInt('guest', '0');
         $guest = false;
         if ($guest_var == '1') {
             $guest = true;
         }
         $register_var = JRequest::getInt('register', '0');
         $form_register = '';
         $register = false;
         if ($register_var == '1') {
             $register = true;
             $form_register = $this->getRegisterForm();
         }
         // determine layout based on login status
         // Login / Register / Checkout as a guest
         if (empty($user->id) && !($guest || $register)) {
             // Display a form for selecting either to register or to login
             JRequest::setVar('layout', 'form');
             Tienda::load("TiendaHelperRoute", 'helpers.route');
             $helper = new TiendaHelperRoute();
             $view = $this->getView('checkout', 'html');
             $checkout_itemid = $helper->findItemid(array('view' => 'checkout'));
             if (empty($checkout_itemid)) {
                 $checkout_itemid = JRequest::getInt('Itemid');
             }
             $view->assign('checkout_itemid', $checkout_itemid);
             parent::display();
             return;
         }
         if ($guest && $this->defines->get('guest_checkout_enabled') || $register) {
             // Checkout as a Guest
             $order = $this->_order;
             $order = $this->populateOrder(true);
             // now that the order object is set, get the orderSummary html
             $html = $this->getOrderSummary();
             // Get the current step
             $progress = $this->getProgress();
             // get address forms
             $billing_address_form = $this->getAddressForm($this->billing_input_prefix, true);
             $shipping_address_form = $this->getAddressForm($this->shipping_input_prefix, true, true);
             // get all the enabled shipping plugins
             Tienda::load('TiendaHelperPlugin', 'helpers.plugin');
             $plugins = TiendaHelperPlugin::getPluginsWithEvent('onGetShippingPlugins');
             $dispatcher = JDispatcher::getInstance();
             $rates = array();
             if ($plugins) {
                 foreach ($plugins as $plugin) {
                     $results = $dispatcher->trigger("onGetShippingRates", array($plugin->element, $order));
                     foreach ($results as $result) {
                         if (is_array($result)) {
                             foreach ($result as $r) {
                                 $rates[] = $r;
                             }
                         }
                     }
                     // endforeach results
                 }
                 // endforeach plugins
             }
             // endif plugins
             // now display the entire checkout page
             $view = $this->getView('checkout', 'html');
             $view->set('hidemenu', false);
             $view->assign('order', $order);
             $view->assign('register', $register);
             $view->assign('form_register', $form_register);
             $view->assign('billing_address_form', $billing_address_form);
             $view->assign('shipping_address_form', $shipping_address_form);
             $view->assign('orderSummary', $html);
             $view->assign('progress', $progress);
             //$view->assign( 'default_billing_address', $default_billing_address );
             //$view->assign( 'default_shipping_address', $default_shipping_address );
             $view->assign('rates', $rates);
             // Checking whether shipping is required
             $showShipping = false;
             $shipping_layout = "shipping_no";
             $cartsModel = $this->getModel('carts');
             if ($isShippingEnabled = $cartsModel->getShippingIsEnabled()) {
                 $showShipping = true;
             }
             if ($showShipping) {
                 $shipping_layout = "shipping_yes";
                 if (empty($shippingAddress)) {
                     $shipping_layout = "shipping_calculate";
                 }
             }
             $shipping_method_form = $this->getShippingHtml($shipping_layout);
             $view->assign('showShipping', $showShipping);
             $view->assign('shipping_method_form', $shipping_method_form);
             JRequest::setVar('layout', 'guest');
         } else {
             // Already Logged in, a traditional checkout
             $order = $this->_order;
             $order = $this->populateOrder(false);
             // now that the order object is set, get the orderSummary html
             $html = $this->getOrderSummary();
             // Get the current step
             $progress = $this->getProgress();
             $user_id = $this->user->id;
             $addresses = array();
             JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
             $model = JModel::getInstance('addresses', 'TiendaModel');
             if (!empty($user_id)) {
                 $model->setState("filter_userid", $user_id);
                 $model->setState("filter_deleted", 0);
                 $addresses = $model->getList();
             }
             $billingAddress = $order->getBillingAddress();
             $shippingAddress = $order->getShippingAddress();
             // get address forms
             $billing_address_form = $this->getAddressForm($this->billing_input_prefix);
             $shipping_address_form = $this->getAddressForm($this->shipping_input_prefix, false, true);
             // get the default shipping and billing addresses, if possible
             $default_billing_address = $this->getAddressHtml(@$billingAddress->address_id);
             $default_shipping_address = $this->getAddressHtml(@$shippingAddress->address_id);
             // now display the entire checkout page
             $view = $this->getView('checkout', 'html');
             $view->set('hidemenu', false);
             $view->assign('order', $order);
             $view->assign('addresses', $addresses);
             $view->assign('billing_address', $billingAddress);
             $view->assign('shipping_address', $shippingAddress);
             $view->assign('billing_address_form', $billing_address_form);
             $view->assign('shipping_address_form', $shipping_address_form);
             $view->assign('orderSummary', $html);
             $view->assign('progress', $progress);
             $view->assign('default_billing_address', $default_billing_address);
             $view->assign('default_shipping_address', $default_shipping_address);
             // Check whether shipping is required
             $showShipping = false;
             $shipping_layout = "shipping_no";
             $cartsModel = $this->getModel('carts');
             if ($isShippingEnabled = $cartsModel->getShippingIsEnabled()) {
                 $showShipping = true;
             }
             if ($showShipping) {
                 $shipping_layout = "shipping_yes";
                 if (empty($shippingAddress)) {
                     $shipping_layout = "shipping_calculate";
                 }
             }
             $shipping_method_form = $this->getShippingHtml($shipping_layout);
             $view->assign('showShipping', $showShipping);
             $view->assign('shipping_method_form', $shipping_method_form);
             JRequest::setVar('layout', 'default');
         }
         $dispatcher = JDispatcher::getInstance();
         ob_start();
         $dispatcher->trigger('onBeforeDisplaySelectShipping', array($order));
         $view->assign('onBeforeDisplaySelectShipping', ob_get_contents());
         ob_end_clean();
         ob_start();
         $dispatcher->trigger('onAfterDisplaySelectShipping', array($order));
         $view->assign('onAfterDisplaySelectShipping', ob_get_contents());
         ob_end_clean();
     }
     $view->setTask(true);
     $view->assign('default_country', $this->default_country);
     $view->assign('default_country_id', $this->default_country_id);
     parent::display();
     return;
 }
Beispiel #13
0
 /**
  * Finds the itemid for the set of variables provided in $needles
  * 
  * @param array $needles
  * @return unknown_type
  */
 public static function findItemid($needles = array('view' => 'products', 'task' => '', 'filter_category' => '', 'id' => ''))
 {
     // populate the array of menu items for the extension
     if (empty(self::$itemids)) {
         self::$itemids = array();
         // method=upgrade KILLS all of the useful properties in the __menus table,
         // so we need to do this manually
         // $menus      = JApplication::getMenu('site', array());
         // $component  = JComponentHelper::getComponent('com_tienda');
         // $items      = $menus->getItems('componentid', $component->id);
         $items = self::getItems();
         if (empty($items)) {
             return null;
         }
         // TODO Move this into the getItems() ?
         foreach ($items as $item) {
             if (!empty($item->query) && !empty($item->query['view'])) {
                 // reconstruct each url query, in case admin has created custom URLs
                 $query = "";
                 $view = $item->query['view'];
                 $query .= "&view={$view}";
                 if (!empty($item->query['task'])) {
                     $task = $item->query['task'];
                     $query .= "&task={$task}";
                 }
                 if (!empty($item->query['filter_category'])) {
                     $filter_category = $item->query['filter_category'];
                     $query .= "&filter_category={$filter_category}";
                 }
                 if (!empty($item->query['id'])) {
                     $id = $item->query['id'];
                     $query .= "&id={$id}";
                 }
                 // set the itemid in the cache array
                 if (empty(self::$itemids[$query])) {
                     self::$itemids[$query] = $item->id;
                 }
             }
         }
     }
     // Make this search the array of self::$itemids, matching with the properties of the $needles array
     // return null if nothing found
     // reconstruct query based on needle
     $query = "";
     if (!empty($needles['view'])) {
         $view = $needles['view'];
         $query .= "&view={$view}";
     }
     if (!empty($needles['task'])) {
         $task = $needles['task'];
         $query .= "&task={$task}";
     }
     if (!empty($needles['filter_category'])) {
         $filter_category = $needles['filter_category'];
         $query .= "&filter_category={$filter_category}";
     }
     if (!empty($needles['id'])) {
         $id = $needles['id'];
         $query .= "&id={$id}";
     }
     // if the query exists in the itemid cache, return it
     if (!empty(self::$itemids[$query])) {
         return self::$itemids[$query];
     }
     return null;
 }
Beispiel #14
0
 /**
  * 
  * Enter description here ...
  * @return return_type
  */
 public function shareitems()
 {
     JRequest::checkToken() or jexit('Invalid Token');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     // get the email addresses, cutting list off at 10 unique emails
     $addresses = JRequest::getVar('share_emails', '');
     $cids = JRequest::getVar('cid', array(0), '', 'array');
     // explode them to an array
     $recipients = array();
     if ($nlsv = explode("\n", $addresses)) {
         foreach ($nlsv as $email) {
             $email = trim($email);
             if (!empty($email) && !in_array($email, $recipients)) {
                 $recipients[] = $email;
             }
         }
     }
     Tienda::load("TiendaHelperRoute", 'helpers.route');
     $router = new TiendaHelperRoute();
     $redirect = JRoute::_("index.php?option=com_tienda&view=wishlists&tmpl=component&task=share&cid[]=" . implode(',', $cids), false);
     // if no emails, fail
     if (empty($recipients)) {
         $this->messagetype = 'notice';
         $this->message = JText::_('COM_TIENDA_PLEASE_PROVIDE_EMAIL_RECIPIENTS');
         $this->setRedirect($redirect, $this->message, $this->messagetype);
         return;
     }
     // create the list of items to be shared, with name & link to each item's detail page
     $model = $this->getModel($this->get('suffix'));
     $model->setState('filter_ids', $cids);
     $model->setState('filter_privacy', array(1, 2));
     $items = $model->getList(true);
     if (!count($items)) {
         $this->messagetype = 'error';
         $this->message = JText::_('COM_TIENDA_CANT_SHARE_PRIVATE_WISHLIST');
         $this->setRedirect(JRoute::_("index.php?option=com_tienda&view=wishlists&Itemid=" . $router->findItemid(array('view' => 'wishlists')), false), $this->message, $this->messagetype);
         return;
     }
     $model_items = $this->getModel('wishlistitems');
     $wishlist_items = array();
     foreach ($items as $wishlist) {
         $model_items->setState('filter_wishlist', $wishlist->wishlist_id);
         $w_items = $model_items->getList(true);
         $wishlist_items = array_merge($wishlist_items, $w_items);
     }
     $share_items_html = '';
     if (!empty($wishlist_items)) {
         Tienda::load('TiendaHelperProduct', 'helpers.product');
         $products_model = JModel::getInstance('Products', 'TiendaModel');
         $share_items_html .= JText::_('COM_TIENDA_WISHLIST_EMAIL_LIST_ITEMS') . '<ul>';
         foreach ($wishlist_items as $item) {
             $item->link = "index.php?option=com_tienda&view=products&task=view&id=" . $item->product_id;
             $attributes = explode(',', $item->product_attributes);
             $tbl = JTable::getInstance('ProductAttributes', 'TiendaTable');
             $tbl_opt = JTable::getInstance('ProductAttributeOptions', 'TiendaTable');
             $product_name = $item->product_name;
             $attr_list = array();
             for ($i = 0, $c = count($attributes); $i < $c; $i++) {
                 $tbl_opt->load($attributes[$i]);
                 $tbl->load($tbl_opt->productattribute_id);
                 $item->link .= '&attribute_' . $tbl_opt->productattribute_id . '=' . $attributes[$i];
                 $attr_list[] = $tbl->productattribute_name . ': ' . $tbl_opt->productattributeoption_name;
             }
             if (count($attr_list)) {
                 $product_name .= ' (' . implode('; ', $attr_list) . ')';
             }
             $item->itemid = $products_model->getItemid($item->product_id);
             if (empty($item->itemid)) {
                 $item->itemid = $router->findItemid(array('view' => 'products', 'filter_category' => '1'));
             }
             $item->link = substr(JURI::base(), 0, -1) . JRoute::_($item->link . "&Itemid=" . $item->itemid);
             $share_items_html .= '<li>';
             $share_items_html .= '<a href="' . $item->link . '">';
             $share_items_html .= $product_name;
             $share_items_html .= '</a>';
             $share_items_html .= '</li>';
         }
         $share_items_html .= '</ul>';
     }
     // set the mailfrom & reply-to
     $mainframe = JFactory::getApplication();
     $sitename = $mainframe->getCfg('sitename');
     $siteurl = JURI::base();
     $user = JFactory::getUser();
     $replyto = $user->email;
     $replytoname = $user->name;
     $mailfrom = $replyto;
     $fromname = $replytoname;
     // create body and subject of email
     $site_email = '<a href="' . $siteurl . '" target="_blank">' . $sitename . '</a>';
     $share_message = JRequest::getVar('share_message', '');
     $subject = JText::sprintf("COM_TIENDA_SHARE_WISHLIST_EMAIL_SUBJECT", $sitename);
     $body = JText::sprintf("COM_TIENDA_SHARE_WISHLIST_EMAIL_BODY", $replytoname, $site_email);
     $body .= JText::sprintf("COM_TIENDA_MESSAGE_FROM_SENDER", $share_message);
     $body .= $share_items_html;
     $this->use_html = true;
     // foreach email address, send the email
     $max_recipients = '10';
     $count = count($recipients) > $max_recipients ? $max_recipients : count($recipients);
     for ($i = 0; $i < $count; $i++) {
         $recipient = $recipients[$i];
         if (empty($done[$recipient])) {
             $done[$recipient] = $recipient;
             if ($send = $this->_sendMail($mailfrom, $fromname, $recipient, $subject, $body, null, null, null, null, null, $replyto, $replytoname)) {
                 $success = true;
                 $done[$recipient] = $recipient;
             }
         }
     }
     // redirect to wishlist with message
     $view = $this->getView($this->get('suffix'), JFactory::getDocument()->getType());
     $view->set('hidemenu', true);
     $view->set('_doTask', true);
     $view->setModel($model, true);
     $view->assign('only_redirect', true);
     $view->setLayout('share');
     $view->display();
     return;
 }
Beispiel #15
0
<?php

defined('_JEXEC') or die('Restricted access');
if ($this->only_redirect) {
    Tienda::load("TiendaHelperRoute", 'helpers.route');
    $router = new TiendaHelperRoute();
    ?>
<script type="text/javascript">
	tiendaJQ( function() {
		window.parent.location = '<?php 
    echo JRoute::_("index.php?option=com_tienda&view=wishlists&email=true&Itemid=" . $router->findItemid(array('view' => 'wishlists')), false);
    ?>
';
		window.close();
	});
</script>
<?php 
} else {
    ?>

	<div id='page-title-navigation'>
	    <h1 id="page-title"><?php 
    echo JText::_('COM_TIENDA_SHARE_WISHLIST_ITEMS');
    ?>
</h1>
	</div>
	
	<form action="<?php 
    echo JRoute::_('index.php?option=com_tienda&view=wishlists&task=shareitems&tmpl=component');
    ?>
" method="post" name="adminForm" enctype="multipart/form-data">
Beispiel #16
0
<?php

defined('_JEXEC') or die('Restricted access');
Tienda::load('TiendaSelect', 'library.select');
$doc = JFactory::getDocument();
$doc->addStyleSheet(JURI::root(true) . '/modules/mod_tienda_manufacturers/tmpl/tienda_manufacturers.css');
?>

<ul id="tienda_manufacturers_mod">
<?php 
foreach ($items as $item) {
    ?>
	<li class="level<?php 
    echo $item->level;
    ?>
">
		<a href="<?php 
    echo TiendaHelperRoute::manufacturer($item->manufacturer_id);
    ?>
"><?php 
    echo $item->manufacturer_name;
    ?>
</a>    
	</li>
<?php 
}
?>
</ul>