Example #1
0
 /**
  * Adds items to the pathway if they aren't already present
  *  
  * @param array $items A full pathway to the category, an array of pathway objects
  * @param int $item_id A default Itemid to use if none is found 
  */
 function insertCategories($items, $item_id = '')
 {
     $app = JFactory::getApplication();
     $pathway = $app->getPathway();
     $pathway_values = $pathway->getPathway();
     // find the array_key of the first item in items that is in pathway
     $found = false;
     $found_key = 0;
     $new_pathway = array();
     foreach ($items as $item) {
         if (!$found) {
             foreach ($pathway_values as $key => $object) {
                 if (!$found) {
                     if ($object->name == $item->name) {
                         $found = true;
                         $found_key = $key;
                     }
                 }
             }
         }
     }
     foreach ($pathway_values as $key => $object) {
         if ($key < $found_key || !$found) {
             $new_pathway[] = $object;
         }
     }
     // $new_pathway now has the pathway UP TO where we should inject the category pathway
     foreach ($items as $item) {
         $category_itemid = !empty($item_id) ? $item_id : Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($item->id, true);
         $item->link .= "&Itemid=" . $category_itemid;
         $new_pathway[] = $item;
     }
     $pathway->setPathway($new_pathway);
     return $new_pathway;
 }
Example #2
0
 public function getPAOCategories($category_ids)
 {
     $model = Tienda::getClass('TiendaModelProducts', 'models.products');
     $model->setState('filter_published_date', $this->state['filter_published_date']);
     $return = $model->getPAOCategories($category_ids);
     return $return;
 }
Example #3
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');
     JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
     // get the model
     $model = JModel::getInstance('Manufacturers', 'TiendaModel');
     // 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.manufacturer_name');
     // set the states based on the parameters
     // using the set filters, get a list
     $items = $model->getList();
     if (!empty($items)) {
         foreach ($items as $item) {
             // this gives error
             $item->itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->manufacturer($item->manufacturer_id, false);
             if (empty($item->itemid)) {
                 $item->itemid = $this->params->get('itemid');
             }
         }
     }
     return $items;
 }
Example #4
0
 function plgTiendaProduct_customfields(&$subject, $config)
 {
     parent::__construct($subject, $config);
     $this->loadLanguage('', JPATH_ADMINISTRATOR);
     //Check the installation integrity
     $helper = Tienda::getClass('TiendaHelperDiagnosticsProductCustomFields', 'product_customfields.diagnostic', array('site' => 'site', 'type' => 'plugins', 'ext' => 'tienda'));
     $helper->checkInstallation();
 }
Example #5
0
 /**
  * Method to build the pathway/breadcrumbs 
  * @return string
  */
 function pathway()
 {
     $pathway = '';
     $catid = JRequest::getInt('filter_category');
     if ($this->params->get('showhome')) {
         $homeText = $this->params->get('hometext');
         $homeText = empty($homeText) ? JText::_('COM_TIENDA_HOME') : $homeText;
         $pathway .= " <a href='index.php'>" . $homeText . '</a> ';
     }
     // get the root category
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $root = JTable::getInstance('Categories', 'TiendaTable')->getRoot();
     $root_itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($root->category_id, true);
     $catRoot = $this->params->get('showcatroot', '1');
     if ($catRoot && $catid != $root->category_id) {
         $pathway .= $this->getSeparator();
         $link = JRoute::_("index.php?option=com_tienda&view=products&filter_category=" . $root->category_id . "&Itemid=" . $root_itemid, false);
         $rootText = $this->params->get('roottext');
         $rootText = empty($rootText) ? JText::_('COM_TIENDA_ALL_CATEGORIES') : $rootText;
         $pathway .= " <a href='{$link}'>" . $rootText . '</a> ';
     }
     $table = JTable::getInstance('Categories', 'TiendaTable');
     $table->load($catid);
     if (empty($table->category_id)) {
         return $pathway;
     }
     $path = $table->getPath();
     foreach (@$path as $cat) {
         if (!$cat->isroot) {
             if (!($itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($cat->category_id, true))) {
                 $itemid = $root_itemid;
             }
             $slug = $cat->category_alias ? ":{$cat->category_alias}" : "";
             $link = JRoute::_("index.php?option=com_tienda&view=products&filter_category=" . $cat->category_id . $slug . "&Itemid=" . $itemid, false);
             if (!empty($pathway)) {
                 $pathway .= $this->getSeparator();
             }
             $pathway .= " <a href='{$link}'>" . JText::_($cat->category_name) . '</a> ';
         }
     }
     if (!empty($pathway)) {
         $pathway .= $this->getSeparator();
     }
     if ($linkSelf = $this->params->get('linkself')) {
         if (!($itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($table->category_id, true))) {
             $itemid = $root_itemid;
         }
         $slug = $table->category_alias ? ":{$table->category_alias}" : "";
         $link = JRoute::_("index.php?option=com_tienda&view=products&filter_category=" . $table->category_id . $slug . "&Itemid=" . $itemid, false);
         $pathway .= " <a href='{$link}'>" . JText::_($table->category_name) . '</a> ';
     } else {
         $pathway .= JText::_($table->category_name);
     }
     return $pathway;
 }
Example #6
0
 /**
  * 
  * @param unknown_type $updateNulls
  * @return unknown_type
  */
 function store($updateNulls = false)
 {
     if ($return = parent::store($updateNulls)) {
         if ($this->notify_customer == '1') {
             Tienda::load("TiendaHelperBase", 'helpers._base');
             $helper = TiendaHelperBase::getInstance('Email');
             $model = Tienda::getClass("TiendaModelSubscriptions", "models.subscriptions");
             $model->setId($this->subscription_id);
             $subscription = $model->getItem();
             $helper->sendEmailNotices($subscription, 'subscription');
         }
     }
     return $return;
 }
Example #7
0
 /**
  * 
  * @param unknown_type $updateNulls
  * @return unknown_type
  */
 function store($updateNulls = false)
 {
     if ($return = parent::store($updateNulls)) {
         if ($this->notify_customer == '1') {
             Tienda::load("TiendaHelperBase", 'helpers._base');
             $helper = TiendaHelperBase::getInstance('Email');
             $model = Tienda::getClass("TiendaModelOrders", "models.orders");
             $model->setId($this->order_id);
             // this isn't necessary because you specify the requested PK id as a getItem() argument
             $order = $model->getItem($this->order_id, true);
             $helper->sendEmailNotices($order, 'order');
         }
     }
     return $return;
 }
Example #8
0
 /**
  * Displays search results
  *
  * (non-PHPdoc)
  * @see tienda/admin/TiendaController#display($cachable)
  */
 function display($cachable = false, $urlparams = false)
 {
     JRequest::setVar('view', $this->get('suffix'));
     $view = $this->getView($this->get('suffix'), JFactory::getDocument()->getType());
     $model = $this->getModel($this->get('suffix'));
     $this->_setModelState();
     if ($items = $model->getList()) {
         foreach ($items as $row) {
             $row->category_id = 0;
             $categories = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getCategories($row->product_id);
             if (!empty($categories)) {
                 $row->category_id = $categories[0];
             }
             $itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->product($row->product_id, $row->category_id, true);
             $row->itemid = empty($itemid) ? JRequest::getInt('Itemid') : $itemid;
         }
     }
     parent::display($cachable, $urlparams);
 }
Example #9
0
 /**
  * Processes a new order
  *
  * @param $order_id
  * @return unknown_type
  */
 public function processStringForOrder($order_id, &$string)
 {
     // get the order
     $model = JModel::getInstance('Orders', 'TiendaModel');
     $model->setId($order_id);
     $order = $model->getItem();
     $this->_orderFromModel = $order;
     $orderTable = $model->getTable();
     $orderTable->load($order_id);
     $this->_order = $orderTable;
     $this->_date = JFactory::getDate();
     if ($order->user_id < Tienda::getGuestIdStart()) {
         $this->_user = $order->user_id;
     } else {
         $this->_user = JFactory::getUser($order->user_id);
     }
     $this->products_model = Tienda::getClass('TiendaModelProducts', 'models.products');
     return $this->processString($string);
 }
Example #10
0
 public function getGroups()
 {
     $groups = array();
     if (empty($this->user->id)) {
         $groups[] = $this->defines->get('default_user_group', '1');
         return $groups;
     }
     $model = Tienda::getClass("TiendaModelUserGroups", 'models.usergroups');
     $model->setState('filter_user', $this->user->id);
     if ($usergroups = $model->getList()) {
         foreach ($usergroups as $usergroup) {
             $groups[] = $usergroup->group_id;
         }
     }
     if (empty($groups)) {
         $groups = array();
         $groups[] = $this->defines->get('default_user_group', '1');
     }
     return $groups;
 }
Example #11
0
 /**
  * Sample use of the products model for getting products with certain properties
  * See admin/models/products.php for all the filters currently built into the model 
  * 
  * @param $parameters
  * @return unknown_type
  */
 function getProducts()
 {
     // 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');
     JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
     $user = JFactory::getUser();
     // get the model
     $model = JModel::getInstance('OrderItems', 'TiendaModel');
     $model->setState('limit', $this->params->get('max_number', '5'));
     $model->setState('filter_userid', $user->id);
     $model->setState('order', 'created_date');
     $model->setState('direction', 'DESC');
     $query = $model->getQuery();
     $query->select("MAX(o.order_id) AS order_id");
     $query->select("MAX(o.created_date) AS created_date");
     if ($this->params->get('display_downloads_only')) {
         $query->join('LEFT', '#__tienda_productfiles AS files ON tbl.product_id = files.product_id');
         $query->where("files.productfile_id IS NOT NULL");
     }
     $query->group('tbl.product_id');
     $model->setQuery($query);
     $router = Tienda::getClass('TiendaHelperRoute', 'helpers.route');
     $product = Tienda::getClass('TiendaHelperProduct', 'helpers.product');
     if ($items = $model->getList()) {
         foreach ($items as $item) {
             $category = null;
             if ($categories = $product->getCategories($item->product_id)) {
                 $category = $categories[0];
             }
             $item->link = $router->product($item->product_id, $category);
         }
     }
     return $items;
 }
Example #12
0
 function __construct(&$subject, $config)
 {
     parent::__construct($subject, $config);
     $language = JFactory::getLanguage();
     $language->load('plg_tienda_' . $this->_element, JPATH_ADMINISTRATOR, 'en-GB', true);
     $language->load('plg_tienda_' . $this->_element, JPATH_ADMINISTRATOR, null, true);
     $this->account_id = $this->params->get('account_id', '');
     // Load helper
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         // Joomla! 1.6+ code here
         $this->helper = Tienda::getClass('TiendaHelperGoogle', 'googleproducts.googleproducts.helper', array('site' => 'site', 'type' => 'plugins', 'ext' => 'tienda'));
     } else {
         // Joomla! 1.5 code here
         $this->helper = Tienda::getClass('TiendaHelperGoogle', 'googleproducts.helper', array('site' => 'site', 'type' => 'plugins', 'ext' => 'tienda'));
     }
     // Params
     $this->helper->setUsername($this->params->get('username', ''));
     $this->helper->setPassword($this->params->get('password', ''));
     $this->helper->service = 'structuredcontent';
     $this->helper->source = JURI::base();
     $this->buildfeed = $this->params->get('build_feed', '0');
     //$this->helper->source = 'http://www.weble.it';
 }
 /**
  * Processing the payment
  * 
  * @param $data     array form post data
  * @return string   HTML to display
  */
 function _process($data)
 {
     $errors = array();
     // load the orderpayment record and set some values
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $orderpayment_id = $data['orderpayment_id'];
     $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable');
     $orderpayment->load($orderpayment_id);
     $orderpayment->transaction_details = $data['orderpayment_type'];
     $orderpayment->transaction_id = $data['orderpayment_id'];
     $orderpayment->transaction_status = "Payment Incomplete";
     // check the stored amount against the payment amount
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => ''));
     $respond_amount = TiendaHelperBase::number($data['orderpayment_amount'], array('thousands' => ''));
     if ($stored_amount != $respond_amount) {
         $errors[] = JText::_('TIENDA ALPHAUSERPOINTS PAYMENT MESSAGE AMOUNT INVALID');
         $errors[] = $stored_amount . " != " . $respond_amount;
     }
     // check if user has enough points
     $userpoints = $this->getUserpoints();
     if ($data['amount_points'] > $userpoints) {
         $errors[] = JText::_('TIENDA ALPHAUSERPOINTS PAYMENT MESSAGE NOT ENOUGH POINTS');
     }
     // set the order's new status and update quantities if necessary
     Tienda::load('TiendaHelperOrder', 'helpers.order');
     Tienda::load('TiendaHelperCarts', 'helpers.carts');
     $order = JTable::getInstance('Orders', 'TiendaTable');
     $order->load($orderpayment->order_id);
     if (count($errors)) {
         // if an error occurred
         $order->order_state_id = $this->params->get('failed_order_state', '10');
         // FAILED
         $setOrderPaymentReceived = false;
         $send_email = false;
     } else {
         $order->order_state_id = $this->params->get('payment_received_order_state', '17');
         // PAYMENT RECEIVED
         $orderpayment->transaction_status = "Payment Received";
         //reduce number of alphauserpoints
         $errors[] = $this->reduceUserpoints($data['amount_points']);
         // do post payment actions
         $setOrderPaymentReceived = true;
         // send email
         $send_email = true;
     }
     // save the order
     if (!$order->save()) {
         $errors[] = $order->getError();
     }
     // save the orderpayment
     if (!$orderpayment->save()) {
         $errors[] = $orderpayment->getError();
     }
     if (!empty($setOrderPaymentReceived)) {
         $this->setOrderPaymentReceived($orderpayment->order_id);
     }
     if ($send_email) {
         // send notice of new order
         Tienda::load("TiendaHelperBase", 'helpers._base');
         $helper = TiendaHelperBase::getInstance('Email');
         $model = Tienda::getClass("TiendaModelOrders", "models.orders");
         $model->setId($orderpayment->order_id);
         $order = $model->getItem();
         $helper->sendEmailNotices($order, 'new_order');
     }
     return count($errors) ? implode("\n", $errors) : '';
 }
Example #14
0
 /**
  *
  * Enter description here ...
  * @return unknown_type
  */
 function sendShipmentAjax()
 {
     $model = JModel::getInstance('Orders', 'TiendaModel');
     $model->setId(JRequest::getInt('order_id'));
     $order = $model->getItem();
     if ($this->sendShipment($order)) {
         $html = JText::_('COM_TIENDA_SHIPMENT_SENT') . '<br />';
         $path = Tienda::getPath('order_files') . DS . $order->order_id;
         $helper = Tienda::getClass('TiendaHelperProduct', 'helpers.product');
         $labels = $helper->getServerFiles($path);
         $plugin = $this->_getMe();
         $plugin_id = $plugin->id;
         $vars = new JObject();
         $vars->link = "index.php?option=com_plugins&view=plugin&client=site&task=edit&cid[]={$plugin_id}";
         $vars->id = $plugin_id;
         $vars->labels = $labels;
         $vars->order_id = $order->order_id;
         $html .= $this->_getLayout('labels', $vars);
         return $html;
     } else {
         return JText::_('COM_TIENDA_SHIPMENT_FAILED') . '<br />' . $this->getError();
     }
 }
 function _process($data)
 {
     $post = JRequest::get('post');
     $orderpayment_id = @$data['ssl_invoice_number'];
     $errors = array();
     $send_email = false;
     // load the orderpayment record and set some values
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable');
     $orderpayment->load($orderpayment_id);
     if (empty($orderpayment_id) || empty($orderpayment->orderpayment_id)) {
         $errors[] = JText::_('VIRTUALMERCHANT MESSAGE INVALID ORDERPAYMENTID');
         return count($errors) ? implode("\n", $errors) : '';
     }
     $orderpayment->transaction_details = $data['ssl_result_message'];
     $orderpayment->transaction_id = $data['ssl_txn_id'];
     $orderpayment->transaction_status = $data['ssl_result'];
     // check the stored amount against the payment amount
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => ''));
     $respond_amount = TiendaHelperBase::number($data['ssl_amount'], array('thousands' => ''));
     if ($stored_amount != $respond_amount) {
         $errors[] = JText::_('VIRTUALMERCHANT MESSAGE AMOUNT INVALID');
         $errors[] = $stored_amount . " != " . $respond_amount;
     }
     // set the order's new status and update quantities if necessary
     Tienda::load('TiendaHelperOrder', 'helpers.order');
     Tienda::load('TiendaHelperCarts', 'helpers.carts');
     $order = JTable::getInstance('Orders', 'TiendaTable');
     $order->load($orderpayment->order_id);
     if (count($errors)) {
         // if an error occurred
         $order->order_state_id = $this->params->get('failed_order_state', '10');
         // FAILED
     } else {
         $order->order_state_id = $this->params->get('payment_received_order_state', '17');
         // PAYMENT RECEIVED
         // do post payment actions
         $setOrderPaymentReceived = true;
         // send email
         $send_email = true;
     }
     // save the order
     if (!$order->save()) {
         $errors[] = $order->getError();
     }
     // save the orderpayment
     if (!$orderpayment->save()) {
         $errors[] = $orderpayment->getError();
     }
     if (!empty($setOrderPaymentReceived)) {
         $this->setOrderPaymentReceived($orderpayment->order_id);
     }
     if ($send_email) {
         // send notice of new order
         Tienda::load("TiendaHelperBase", 'helpers._base');
         $helper = TiendaHelperBase::getInstance('Email');
         $model = Tienda::getClass("TiendaModelOrders", "models.orders");
         $model->setId($orderpayment->order_id);
         $order = $model->getItem();
         $helper->sendEmailNotices($order, 'new_order');
     }
     return count($errors) ? implode("\n", $errors) : '';
     return true;
 }
Example #16
0
 public function getCategories($id, $refresh = false)
 {
     $model = Tienda::getClass('TiendaModelProductCategories', 'models.productcategories');
     $model->setState('filter_product_id', $id);
     $result = $model->getList($refresh);
     return $result;
 }
Example #17
0
<?php

defined('_JEXEC') or die('Restricted access');
?>
<div style="float: left; width: 50%;">
	<fieldset>
		<legend>
			<?php 
echo JText::_('iDevAffiliate Integration');
?>
		</legend>
		<?php 
if (Tienda::getClass('TiendaHelperAmigos', 'helpers.amigos')->isInstalled()) {
    ?>
		<table class="admintable" style="width: 100%;">
			<tr>
				<td style="width: 125px; text-align: right;" class="key hasTip" title="<?php 
    echo JText::_('Commission Rate Override') . '::' . JText::_('Commission Rate Override Tip');
    ?>
" >
				<?php 
    echo JText::_('Commission Rate Override');
    ?>
:
				</td>
				<td>
				<input name="amigos_commission_override" id="amigos_commission_override" value="<?php 
    echo @$row->product_parameters->get('amigos_commission_override');
    ?>
" size="10" maxlength="10" type="text" />
				</td>
Example #18
0
 /**
  * Migrate the images
  * 
  * @param int $product_id
  * @param string $images
  */
 private function _migrateImages($product_id, $images)
 {
     Tienda::load('TiendaImage', 'library.image');
     foreach ($images->children() as $image) {
         $check = false;
         $multiple = false;
         $image = (string) $image;
         if (JURI::isInternal($image)) {
             $internal = true;
             $int_image = JPATH_SITE . DS . $image;
             if (is_dir($int_image)) {
                 $check = JFolder::exists($int_image);
                 $multiple = true;
             } else {
                 $check = JFile::exists($int_image);
             }
             // Now check the extracted images path
             if (!$check) {
                 $dir = $this->_temp_dir . DS . 'images' . DS;
                 if (is_dir($dir . $image)) {
                     $check = JFolder::exists($dir . $image);
                     $multiple = true;
                 } else {
                     $check = JFile::exists($dir . $image);
                 }
                 if ($check) {
                     $image = $dir . $image;
                 }
             } else {
                 $image = $int_image;
             }
         } else {
             $internal = false;
             $check = $this->url_exists($image);
         }
         // Add a single image
         if (!$multiple) {
             $images_to_copy = array($image);
         } else {
             // Fetch the images from the folder and add them
             $images_to_copy = Tienda::getClass("TiendaHelperProduct", 'helpers.product')->getGalleryImages($image);
             foreach ($images_to_copy as &$i) {
                 $i = $image . DS . $i;
             }
         }
         if ($check) {
             foreach ($images_to_copy as $image_to_copy) {
                 if ($internal) {
                     $img = new TiendaImage($image_to_copy);
                 } else {
                     $tmp_path = JFactory::getApplication()->getCfg('tmp_path');
                     $file = fopen($image_to_copy, 'r');
                     $file_content = stream_get_contents($file);
                     fclose($file);
                     $file = fopen($tmp_path . DS . $image_to_copy, 'w');
                     fwrite($file, $file_content);
                     fclose($file);
                     $img = new TiendaImage($tmp_path . DS . $image_to_copy);
                 }
                 Tienda::load('TiendaTableProducts', 'tables.products');
                 $product = JTable::getInstance('Products', 'TiendaTable');
                 $product->load($product_id);
                 $path = $product->getImagePath();
                 $type = $img->getExtension();
                 $img->load();
                 $img->setDirectory($path);
                 // Save full Image
                 $img->save($path . $img->getPhysicalName());
                 // Save Thumb
                 Tienda::load('TiendaHelperImage', 'helpers.image');
                 $imgHelper = TiendaHelperBase::getInstance('Image', 'TiendaHelper');
                 $imgHelper->resizeImage($img, 'product');
             }
         }
     }
 }
Example #19
0
 /**
  *
  * Enter description here ...
  * @param $data
  * @return unknown_type
  */
 public function _processSubscriptionPayment($data)
 {
     // if we're here, a successful payment has been made.
     // the normal notice that requires action.
     // create a subscription_id if no subscr_id record exists
     // set expiration dates
     // add a sub history entry, email the user?
     $errors = array();
     // Check that custom (orderpayment_id) is present, we need it for payment amount verification
     if (empty($data['custom'])) {
         $this->setError(JText::_('PAYPAL MESSAGE INVALID ORDERPAYMENTID'));
         return false;
     }
     // load the orderpayment record and set some values
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable');
     $orderpayment->load($data['custom']);
     if (empty($data['custom']) || empty($orderpayment->orderpayment_id)) {
         $this->setError(JText::_('PAYPAL MESSAGE INVALID ORDERPAYMENTID'));
         return false;
     }
     $orderpayment->transaction_details = $data['transaction_details'];
     $orderpayment->transaction_id = $data['txn_id'];
     $orderpayment->transaction_status = $data['payment_status'];
     if (!$orderpayment->save()) {
         $errors[] = $orderpayment->getError();
     }
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $order = JTable::getInstance('Orders', 'TiendaTable');
     $order->load($data['item_number']);
     $items = $order->getItems();
     // Update orderitem_status
     $order_item = $order->getRecurringItem();
     $orderitem = JTable::getInstance('OrderItems', 'TiendaTable');
     $orderitem->orderitem_id = $order_item->orderitem_id;
     $orderitem->orderitem_status = '1';
     $orderitem->save();
     // TODO Here we need to verify the payment amount
     // if no subscription exists for this subscr_id,
     // create new subscription for the user
     $subscription = JTable::getInstance('Subscriptions', 'TiendaTable');
     $subscription->load(array('transaction_id' => $data['subscr_id']));
     if (empty($subscription->subscription_id)) {
         $date = JFactory::getDate();
         // create new subscription
         // if recurring trial, set it
         // for the order's recurring_trial_period_interval
         // using its recurring_trial_period_unit
         // otherwise, do the normal recurring_period_interval
         // and the recurring_period_unit
         $recurring_period_unit = $order->recurring_period_unit;
         $recurring_period_interval = $order->recurring_period_interval;
         if (!empty($order->recurring_trial)) {
             $recurring_period_unit = $order->recurring_trial_period_unit;
             $recurring_period_interval = $order->recurring_trial_period_interval;
         }
         $subscription->user_id = $order->user_id;
         $subscription->order_id = $order->order_id;
         $subscription->product_id = $orderitem->product_id;
         $subscription->orderitem_id = $orderitem->orderitem_id;
         $subscription->transaction_id = $data['subscr_id'];
         $subscription->created_datetime = $date->toMySQL();
         $subscription->subscription_enabled = '1';
         switch ($recurring_period_unit) {
             case "Y":
                 $period_unit = "YEAR";
                 break;
             case "M":
                 $period_unit = "MONTH";
                 break;
             case "W":
                 $period_unit = "WEEK";
                 break;
             case "D":
             default:
                 $period_unit = "DAY";
                 break;
         }
         $database = JFactory::getDBO();
         $query = " SELECT DATE_ADD('{$subscription->created_datetime}', INTERVAL {$recurring_period_interval} {$period_unit} ) ";
         $database->setQuery($query);
         $subscription->expires_datetime = $database->loadResult();
         if (!$subscription->save()) {
             $this->setError($subscription->getError());
             return false;
         }
         // add a sub history entry, email the user?
         $subscriptionhistory = JTable::getInstance('SubscriptionHistory', 'TiendaTable');
         $subscriptionhistory->subscription_id = $subscription->subscription_id;
         $subscriptionhistory->subscriptionhistory_type = 'creation';
         $subscriptionhistory->created_datetime = $date->toMySQL();
         $subscriptionhistory->notify_customer = '0';
         // notify customer of new trial subscription?
         $subscriptionhistory->comments = JText::_('NEW SUBSCRIPTION CREATED');
         $subscriptionhistory->save();
     } else {
         // subscription exists, just update its expiration date
         // based on normal interval and period
         switch ($order->recurring_period_unit) {
             case "Y":
                 $period_unit = "YEAR";
                 break;
             case "M":
                 $period_unit = "MONTH";
                 break;
             case "W":
                 $period_unit = "WEEK";
                 break;
             case "D":
             default:
                 $period_unit = "DAY";
                 break;
         }
         $database = JFactory::getDBO();
         $today = $date = JFactory::getDate();
         $query = " SELECT DATE_ADD('{$today}', INTERVAL {$order->recurring_period_interval} {$period_unit} ) ";
         $database->setQuery($query);
         $subscription->expires_datetime = $database->loadResult();
         if (!$subscription->save()) {
             $this->setError($subscription->getError());
             return false;
         }
         // add a sub history entry, email the user?
         $subscriptionhistory = JTable::getInstance('SubscriptionHistory', 'TiendaTable');
         $subscriptionhistory->subscription_id = $subscription->subscription_id;
         $subscriptionhistory->subscriptionhistory_type = 'payment';
         $subscriptionhistory->created_datetime = $date->toMySQL();
         $subscriptionhistory->notify_customer = '0';
         // notify customer of new trial subscription?
         $subscriptionhistory->comments = JText::_('NEW SUBSCRIPTION PAYMENT RECEIVED');
         $subscriptionhistory->save();
     }
     if (count($items) == '1') {
         // update order status
         Tienda::load('TiendaHelperOrder', 'helpers.order');
         Tienda::load('TiendaHelperCarts', 'helpers.carts');
         $order->order_state_id = $this->params->get('payment_received_order_state', '17');
         // PAYMENT RECEIVED
         // do post payment actions
         $setOrderPaymentReceived = true;
         // send email
         $send_email = true;
         // save the order
         if (!$order->save()) {
             $errors[] = $order->getError();
         }
         if (!empty($setOrderPaymentReceived)) {
             $this->setOrderPaymentReceived($orderpayment->order_id);
         }
         if ($send_email) {
             // send notice of new order
             Tienda::load("TiendaHelperBase", 'helpers._base');
             $helper = TiendaHelperBase::getInstance('Email');
             $model = Tienda::getClass("TiendaModelOrders", "models.orders");
             $model->setId($orderpayment->order_id);
             $order = $model->getItem();
             $helper->sendEmailNotices($order, 'new_order');
         }
     }
     $error = count($errors) ? implode("\n", $errors) : '';
     if (!empty($error)) {
         $this->setError($error);
         return false;
     }
     return true;
 }
Example #20
0
 /**
  * Processes the sale payment
  *
  * @param array $data IPN data
  * @return boolean Did the IPN Validate?
  * @access protected
  */
 function _processSale($data, $ipnValidationFailed = '')
 {
     $send_email = false;
     /*
      * validate the payment data
      */
     $errors = array();
     if (!empty($ipnValidationFailed)) {
         $errors[] = $ipnValidationFailed;
     }
     // is the recipient correct?
     if (empty($data['receiver_email']) || $data['receiver_email'] != $this->_getParam('merchant_email')) {
         $errors[] = JText::_('PAYPAL MESSAGE RECEIVER INVALID');
     }
     // load the orderpayment record and set some values
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable');
     $orderpayment->load($data['custom']);
     $orderpayment->transaction_details = $data['transaction_details'];
     $orderpayment->transaction_id = $data['txn_id'];
     $orderpayment->transaction_status = $data['payment_status'];
     // check the stored amount against the payment amount
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => ''));
     $respond_amount = TiendaHelperBase::number($data['mc_gross'], array('thousands' => ''));
     if ($stored_amount != $respond_amount) {
         $errors[] = JText::_('PAGSEGURO MESSAGE PAYMENT AMOUNT INVALID');
         $errors[] = $stored_amount . " != " . $respond_amount;
     }
     // check the payment status
     if (empty($data['payment_status']) || $data['payment_status'] != 'Completed' && $data['payment_status'] != 'Pending') {
         $errors[] = JText::sprintf('PAYPAL MESSAGE STATUS INVALID', @$data['payment_status']);
     }
     // set the order's new status and update quantities if necessary
     JLoader::import('com_tienda.helpers.order', JPATH_ADMINISTRATOR . '/components');
     JLoader::import('com_tienda.helpers.carts', JPATH_ADMINISTRATOR . '/components');
     $order = JTable::getInstance('Orders', 'TiendaTable');
     $order->load($orderpayment->order_id);
     if (count($errors)) {
         // if an error occurred
         $order->order_state_id = $this->params->get('failed_order_state', '10');
         // FAILED
     } elseif (@$data['payment_status'] == 'Pending') {
         // if the transaction has the "pending" status,
         $order->order_state_id = Tienda::getInstance('pending_order_state', '1');
         // PENDING
         // Update quantities for echeck payments
         TiendaHelperOrder::updateProductQuantities($orderpayment->order_id, '-');
         // remove items from cart
         TiendaHelperCarts::removeOrderItems($orderpayment->order_id);
     } else {
         $order->order_state_id = $this->params->get('payment_received_order_state', '17');
         // PAYMENT RECEIVED
         // do post payment actions
         $setOrderPaymentReceived = true;
         // send email
         $send_email = true;
     }
     // save the order
     if (!$order->save()) {
         $errors[] = $order->getError();
     }
     // save the orderpayment
     if (!$orderpayment->save()) {
         $errors[] = $orderpayment->getError();
     }
     if (!empty($setOrderPaymentReceived)) {
         $this->setOrderPaymentReceived($orderpayment->order_id);
     }
     if ($send_email) {
         // send notice of new order
         Tienda::load("TiendaHelperBase", 'helpers._base');
         $helper = TiendaHelperBase::getInstance('Email');
         $model = Tienda::getClass("TiendaModelOrders", "models.orders");
         $model->setId($orderpayment->order_id);
         $order = $model->getItem();
         $helper->sendEmailNotices($order, 'new_order');
     }
     return count($errors) ? implode("\n", $errors) : '';
 }
Example #21
0
 /**
  * Gets the order items
  * 
  * @return array of TableOrderItems objects
  */
 function getItems()
 {
     // TODO once all references use this getter, we can do fun things with this method, such as fire a plugin event
     JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
     // if empty($items) && !empty($this->order_id), then this is an order from the db,
     // so we grab all the orderitems from the db
     if (empty($this->_items) && !empty($this->order_id)) {
         // TODO Do this?  How will this impact Site::TiendaControllerCheckout->saveOrderItems()?
         //retrieve the order's items
         $model = JModel::getInstance('OrderItems', 'TiendaModel');
         $model->setState('filter_orderid', $this->order_id);
         $model->setState('order', 'tbl.orderitem_name');
         $model->setState('direction', 'ASC');
         $orderitems = $model->getList();
         foreach ($orderitems as $orderitem) {
             unset($table);
             $table = JTable::getInstance('OrderItems', 'TiendaTable');
             $table->load($orderitem->orderitem_id);
             $this->addItem($table);
         }
     }
     $items = $this->_items;
     if (!is_array($items)) {
         $items = array();
     }
     if (empty($this->_itemschecked)) {
         // ensure that the items array only has one recurring item in it
         foreach ($items as $key => $item) {
             $shipping = Tienda::getClass("TiendaHelperProduct", 'helpers.product')->isShippingEnabled($item->product_id);
             if ($shipping) {
                 $this->order_ships = '1';
             }
             if (empty($this->_recurringItemExists) && $item->orderitem_recurs) {
                 // Only one recurring item allowed per order.
                 // If the item is recurring,
                 // check if there already is a recurring item accounted for in the order
                 // if so, remove this one from the order but leave it in the cart and continue
                 // if not, add its properties
                 $this->_recurringItemExists = true;
                 $this->_recurringItem = $item;
                 $this->recurring_payments = $item->recurring_payments;
                 $this->recurring_period_interval = $item->recurring_period_interval;
                 $this->recurring_period_unit = $item->recurring_period_unit;
                 $this->recurring_trial = $item->recurring_trial;
                 $this->recurring_trial_period_interval = $item->recurring_trial_period_interval;
                 $this->recurring_trial_period_unit = $item->recurring_trial_period_unit;
                 $this->recurring_trial_price = $item->recurring_trial_price;
                 $this->recurring_amount = $item->recurring_price;
                 // TODO Add tax?
                 //$this->recurring_amount            = $item->recurring_amount; // TODO Add tax?
                 // TODO Set some kind of _recurring_item property, so it is easy to get the recurring item later?
             } elseif (!empty($this->_recurringItemExists) && $item->orderitem_recurs) {
                 // Only one recurring item allowed per order.
                 // If the item is recurring,
                 // check if there already is a recurring item accounted for in the order
                 // if so, remove this one from the order but leave it in the cart and continue
                 unset($items[$key]);
             }
         }
         $this->_itemschecked = true;
     }
     $this->_items = $items;
     return $this->_items;
 }
Example #22
0
 /**
  *  this is updating the transaction id and staus in case of not completed state
  *	@param  data Array of response
  *	@param  error
  */
 function _saveTransaction($data, $error = '')
 {
     $send_email = false;
     $errors = array();
     if (!empty($error)) {
         $errors[] = $error;
     }
     // load the orderpayment record and set some values
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable');
     $orderpayment->load($data->orderpayment_id);
     //	Svaing Financial order state
     $orderpayment->transaction_details = $data->payment_details;
     // Svaing payment status Completed
     $orderpayment->transaction_status = "Payment Declined";
     // Svaing payment status Completed
     $orderpayment->transaction_status = $data->transactionId;
     // update the orderpayment
     if (!$orderpayment->save()) {
         $errors[] = $orderpayment->getError();
     }
     if ($send_email) {
         // send notice of new order
         Tienda::load("TiendaHelperBase", 'helpers._base');
         $helper = TiendaHelperBase::getInstance('Email');
         $model = Tienda::getClass("TiendaModelOrders", "models.orders");
         $model->setId($orderpayment->order_id);
         $order = $model->getItem();
         $helper->sendEmailNotices($order, 'new_order');
     }
     return count($errors) ? implode("\n", $errors) : '';
 }
Example #23
0
 /**
  * Processes the payment form
  * and returns HTML to be displayed to the user
  * generally with a success/failed message
  *  
  * @param $data     array       form post data
  * @return string   HTML to display
  */
 function _postPayment($data)
 {
     // Process the payment
     $vars = new JObject();
     $orderpayment_id = !empty($data['orderpayment_id']) ? $data['orderpayment_id'] : JRequest::getVar('orderpayment_id');
     $cardtype = !empty($data['cardtype']) ? $data['cardtype'] : JRequest::getVar('cardtype');
     $cardnum = !empty($data['cardnum']) ? $data['cardnum'] : JRequest::getVar('cardnum');
     $cardexp = !empty($data['cardexp']) ? $data['cardexp'] : JRequest::getVar('cardexp');
     $cardcvv = !empty($data['cardcvv']) ? $data['cardcvv'] : JRequest::getVar('cardcvv');
     $formatted = array('cardtype' => $cardtype, 'cardnum' => $cardnum, 'cardexp' => $cardexp, 'cardcvv' => $cardcvv);
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable');
     $orderpayment->load($orderpayment_id);
     $orderpayment->transaction_details = implode("\n", $formatted);
     if ($orderpayment->save()) {
         // Don't remove order quantities until payment is actually received?
         if ($this->params->get('remove_quantities')) {
             Tienda::load('TiendaHelperOrder', 'helpers.order');
             TiendaHelperOrder::updateProductQuantities($orderpayment->order_id, '-');
         }
         // remove items from cart
         Tienda::load('TiendaHelperCarts', 'helpers.carts');
         TiendaHelperCarts::removeOrderItems($orderpayment->order_id);
         // send notice of new order
         Tienda::load("TiendaHelperBase", 'helpers._base');
         $helper = TiendaHelperBase::getInstance('Email');
         $model = Tienda::getClass("TiendaModelOrders", "models.orders");
         $model->setId($orderpayment->order_id);
         $order = $model->getItem();
         $helper->sendEmailNotices($order, 'new_order');
     }
     // display the layout
     $html = $this->_getLayout('postpayment', $vars);
     // append the article with offline payment information
     $html .= $this->_displayArticle();
     return $html;
 }
Example #24
0
 /**
  * This method occurs after payment is attempted,
  * and fires the onPostPayment plugin event
  *
  * @return unknown_type
  */
 function confirmPayment()
 {
     $this->current_step = 3;
     $orderpayment_type = JRequest::getVar('orderpayment_type');
     // Get post values
     $values = JRequest::get();
     // get the order_id from the session set by the prePayment
     $mainframe = JFactory::getApplication();
     $order_id = (int) $mainframe->getUserState('tienda.order_id');
     $itemid_string = null;
     if ($itemid = $this->router->findItemid(array('view' => 'orders'))) {
         $itemid_string = "&Itemid=" . $itemid;
     }
     $order_link = 'index.php?option=com_tienda&view=orders&task=view&id=' . $order_id . $itemid_string;
     $pos_order = $mainframe->getUserState('tienda.pos_order');
     $order = $this->_order;
     $order->load(array('order_id' => $order_id));
     //redirect to the backend since we are doing pos order
     if ($pos_order) {
         // create POS request record
         JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
         $pos_tbl = JTable::getInstance("PosRequests", "TiendaTable");
         $pos_tbl->order_id = 0;
         $pos_tbl->user_id = 0;
         $pos_tbl->mode = 2;
         // mode 2 => front-end
         $pos_tbl->data = base64_encode(@json_encode($values));
         $pos_tbl->save();
         // generate pos_id and time
         $pos_tbl->save();
         // save the final token (with pos_id -> that's why we need to save it twice)
         // build URL for POS
         $uri = JURI::getInstance();
         $uriA = JRequest::get('get');
         $uriA['view'] = 'pos';
         $uriA['task'] = 'display';
         $uriA['subtask'] = 'confirmPayment';
         $uriA['pos_id'] = $pos_tbl->pos_id;
         $uriA['pos_token'] = $pos_tbl->token;
         $uriA['order_id'] = $order_id;
         $uriA['user_id'] = $order->user_id;
         $uriA['nextstep'] = 'step5';
         $uriA['Itemid'] = null;
         $pos_link = $uri->buildQuery(array_filter($uriA));
         $mainframe->redirect(JURI::root() . 'administrator/index.php?' . $pos_link);
     }
     $dispatcher = JDispatcher::getInstance();
     $html = "";
     if (!empty($order->order_hash)) {
         $order_link .= '&h=' . $order->order_hash;
     }
     if (!empty($order_id) && (double) $order->order_total == (double) '0.00') {
         $order->order_state_id = '17';
         // PAYMENT RECEIVED
         $order->save();
         // send notice of new order
         Tienda::load("TiendaHelperBase", 'helpers._base');
         $helper = TiendaHelperBase::getInstance('Email');
         $order_model = Tienda::getClass("TiendaModelOrders", "models.orders");
         $order_model->setId($order_id);
         $order_model_item = $order_model->getItem();
         $helper->sendEmailNotices($order_model_item, 'new_order');
         Tienda::load('TiendaHelperOrder', 'helpers.order');
         TiendaHelperOrder::setOrderPaymentReceived($order_id);
     } else {
         // get the payment results from the payment plugin
         $results = $dispatcher->trigger("onPostPayment", 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 (!empty($order_id)) {
         // Set display
         if (!$this->onepage_checkout) {
             $progress = $this->getProgress();
         }
         $view = $this->getView('checkout', 'html');
         $view->setLayout('postpayment');
         $view->set('_doTask', true);
         $view->assign('order_link', $order_link);
         $view->assign('plugin_html', $html);
         if (!$this->onepage_checkout) {
             $view->assign('progress', $progress);
         }
         // Get and Set Model
         $model = $this->getModel('checkout');
         $view->setModel($model, true);
         // get the articles to display after checkout
         $articles = array();
         $article_id = $this->defines->get('article_checkout');
         if (!empty($article_id)) {
             Tienda::load('TiendaArticle', 'library.article');
             $articles[] = TiendaArticle::display($article_id);
         }
         switch ($order->order_state_id) {
             case "2":
             case "3":
             case "5":
             case "17":
                 $articles = array_merge($articles, $this->getOrderArticles($order_id));
                 // Inject <head> code
                 if ($orders_confirmation_header_code = $this->defines->get('orders_confirmation_header_code')) {
                     Tienda::load('TiendaHelperHead', 'helpers.head');
                     $head_helper = new TiendaHelperHead();
                     if ($string_to_inject = $head_helper->processStringForOrder($order_id, $orders_confirmation_header_code)) {
                         $head_helper->injectIntoHead($string_to_inject);
                     }
                 }
                 break;
             case "7":
             case "8":
             case "9":
             case "10":
             case "14":
                 $article_id = $this->defines->get('article_default_payment_failure');
                 Tienda::load('TiendaArticle', 'library.article');
                 $articles = array(TiendaArticle::display($article_id));
                 break;
         }
         $view->assign('articles', $articles);
         ob_start();
         $dispatcher->trigger('onBeforeDisplayPostPayment', array($order_id));
         $view->assign('onBeforeDisplayPostPayment', ob_get_contents());
         ob_end_clean();
         ob_start();
         $dispatcher->trigger('onAfterDisplayPostPayment', array($order_id));
         $view->assign('onAfterDisplayPostPayment', ob_get_contents());
         ob_end_clean();
         $view->display();
     }
     // set up user_id for cart items for guest account
     if ($order->user_id < Tienda::getGuestIdStart()) {
         Tienda::load('TiendaHelperCarts', 'helpers.cart');
         $session = JFactory::getSession();
         $helper = new TiendaHelperCarts();
         $helper->mergeSessionCartWithUserCart($session->getId(), $order->user_id);
     }
     return;
 }
Example #25
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);
 }
Example #26
0
 /**
  *
  * @return HTML
  */
 function _process()
 {
     $send_email = false;
     $data = JRequest::getVar('DATA', '', 'post');
     // Invalidate data if it is in the wrong format
     if (!preg_match(':^[a-zA-Z0-9]+$:', $data)) {
         $data = '';
     }
     $this->os_info = $this->_getOperatingSystemInfo();
     // set sips checkout type
     // Next line is there to help me to debug
     // should not be removed
     //$data = '2020333732603028502c2360532d5328532d2360522d4360502c4360502c3334502c3330512d2324562d5334592c3324512c33242a2c2360532c2360502d2324502c23602a2c2360552c2360502d433c552e3328572c4048512c2334502c23605435444533303048502c2338502c2324542c4360512c2360582c4344502e3334582d233c2a2c3360532c2360502d4324512d3344502c5048512c2330502c2360582c4360512c2360582c43442a2c3360512c2360502c4360505c224324502c4360502c3360512c4340532c233c552e3330535c224324502c2360502c2338502d5334592d232c2a2c2328582c2360502c4639525c224360522e3360502c2329463c4048502c2340502c2360532e333c585c224324502d4360502c233c512c3324512b4360505c224324512d2360502c2338522c2324522c23242a2c2360592c2360502c4639525c224360532c2360502c4321413b26255438364c512c232160383651413d26254b2b4659453d6048502c3338502c23605334552d2c5c224360502d5360502c2328502c4048502c5340502c2360522e33382a2c2330502c2360512d2425353524412f34455d2330352134353529255c224360532e3360502c2324505c224324502e3360502c23292e335048512c3360502c236051334048512c3324502c2360522c23602a2c2328562c2360502d5344572d3344522d53282adc970880f8cf2717';
     //
     // Récupération de la variable cryptée DATA
     $message = "message=" . $data;
     $pathfile .= " pathfile=" . $this->_getPathfileFileName($this->params->get('pathfile'));
     $bin_response = $this->_getBinPath("response");
     $parm = $message . " " . $pathfile;
     $result = exec("{$bin_response} {$parm}");
     $sips_response_array = explode("!", $result);
     list(, $code, $error, $merchant_id, $merchant_country, $amount, $transaction_id, $payment_means, $transmission_date, $payment_time, $payment_date, $response_code, $payment_certificate, $authorisation_id, $currency_code, $card_number, $cvv_flag, $cvv_response_code, $bank_response_code, $complementary_code, $complementary_info, $return_context, $caddie, $receipt_complement, $merchant_language, $language, $customer_id, $orderpayment_id, $customer_email, $customer_ip_address, $capture_day, $capture_mode, $data) = $sips_response_array;
     if ($code != 0) {
         $errors[] = JText::_('TIENDA_SIPS_RETURN_CODE_INVALID') . " " . $code;
     } elseif ($error != 0) {
         $errors[] = JText::_('TIENDA_SIPS_RETURN_ERROR') . " " . $sips_error;
     } elseif ($merchant_id != $this->params->get('merchant_id')) {
         $errors[] = JText::_('TIENDA_SIPS_MERCHANT_ID_RECEIVED_INVALID');
     } else {
         // load the orderpayment record and set some values
         JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_tienda' . DS . 'tables');
         $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable');
         $orderpayment->load($orderpayment_id);
         if (empty($orderpayment_id) || empty($orderpayment->orderpayment_id)) {
             $errors[] = JText::_('TIENDA_SIPS_INVALID ORDERPAYMENTID');
         }
     }
     if (count($errors)) {
         echo $errors;
         print_r($errors);
         $this->_sendErrorEmail($errors, $sips_response_array);
         return false;
     }
     // check the stored amount against the payment amount
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => ''));
     $respond_amount = TiendaHelperBase::number($amount, array('thousands' => ''));
     if ($stored_amount != $respond_amount) {
         $errors[] = JText::_('TIENDA_SIPS_AMOUNT_INVALID');
         $errors[] = $stored_amount . " != " . $respond_amount;
     }
     // set the order's new status and update quantities if necessary
     Tienda::load('TiendaHelperOrder', 'helpers.order');
     Tienda::load('TiendaHelperCarts', 'helpers.carts');
     $order = JTable::getInstance('Orders', 'TiendaTable');
     $order->load($orderpayment->order_id);
     if (count($errors) or $response_code != '00') {
         if ($response_code != '00') {
             $orderpayment->transaction_details = JText::_('TIENDA_SIPS_RESPONSE_CODE') . $response_code . "\n" . JText::_('TIENDA_SIPS_RESPONSE_CODE_SIPS_ERROR') . constant('TIENDA_SIPS_RESPONSE_' . $response['response_code']) . "\n" . JText::_('TIENDA_SIPS_READ_SIPS_DOCUMENTATION');
         } else {
             $orderpayment->transaction_details = implode(" ", $errors);
         }
         $order->order_state_id = $this->params->get('failed_order_state', '10');
         // FAILED
         // save the order
         if (!$order->save()) {
             $errors[] = $order->getError();
         }
         $send_email = false;
     } else {
         define($credit_card_type, $payment_means);
         $credit_card = split('\\.', $card_number);
         $credit_card_number = $credit_card[0] . ' #### #### ##' . $credit_card[1];
         // TO DO: DECODE TIME AND DATE
         $orderpayment->transaction_details = JText::_('TIENDA_SIPS_TRANSMISSION_DATE') . $transmission_date . "\n" . JText::_('TIENDA_SIPS_RESPONSE_PAYMENT_TIME') . " : " . $payment_time . "\n" . JText::_('TIENDA_SIPS_RESPONSE_PAYMENT_DATE') . " : " . $payment_date . "\n" . JText::_('TIENDA_SIPS_RESPONSE_PAYMENT_CERTIFICATE') . " : " . $payment_certificate . "\n" . JText::_('TIENDA_SIPS_RESPONSE_AUTHORIZATION_ID') . $authorisation_id . "\n" . JText::_('TIENDA_SIPS_RESPONSE_CREDIT_CARD_TYPE') . " : " . constant($credit_card_type) . "\n" . JText::_('TIENDA_SIPS_RESPONSE_CREDIT_CARD_NUMBER') . " : " . $credit_card_number;
         $orderpayment->transaction_id = $transaction_id;
         $orderpayment->transaction_status = $response_code;
         // ???
         $order->order_state_id = $this->params->get('payment_received_order_state', '17');
         // save the order
         if (!$order->save()) {
             $errors[] = $order->getError();
         }
         // PAYMENT RECEIVED
         $this->setOrderPaymentReceived($orderpayment->order_id);
         // send email
         $send_email = true;
     }
     // save the orderpayment
     if (!$orderpayment->save()) {
         $errors[] = $orderpayment->getError();
     }
     if ($send_email) {
         // send notice of new order
         Tienda::load("TiendaHelperBase", 'helpers._base');
         $helper = TiendaHelperBase::getInstance('Email');
         $model = Tienda::getClass("TiendaModelOrders", "models.orders");
         $model->setId($orderpayment->order_id);
         $order = $model->getItem();
         $helper->sendEmailNotices($order, 'new_order');
     }
     return count($errors) ? implode("\n", $errors) : 'processed';
 }
Example #27
0
 function _process($data)
 {
     Tienda::load('TiendaModelOrders', 'models.orders');
     $model = new TiendaModelOrders();
     if (!$data['vs']) {
         // order is not valid
         return JText::_('TIENDA CARDPAY MESSAGE INVALID ORDER') . $this->_generateSignature($data, 2);
     }
     $errors = array();
     $send_email = false;
     if ($this->_generateSignature($data, 2) == $data['sign']) {
         switch ($data['res']) {
             case 'OK':
                 // OK
                 break;
             case 'TOUT':
                 // Time out
                 $errors[] = JText::_('TIENDA CARDPAY MESSAGE PAYMENT TIMEOUT');
                 break;
             default:
                 // something went wrong
             // something went wrong
             case 'FAIL':
                 // transaction failed
                 $errors[] = JText::_('TIENDA CARDPAY MESSAGE PAYMENT FAIL');
                 break;
         }
         $send_email = true;
         // send email!
     } else {
         $errors[] = JText::_('Tienda CARDPAY Message Invalid Signature');
     }
     // check that payment amount is correct for order_id
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable');
     $orderpayment->load(array('order_id' => $data['vs']));
     unset($data['secure_key']);
     $orderpayment->transaction_details = Tienda::dump($data);
     $orderpayment->transaction_id = $data['vs'];
     $orderpayment->transaction_status = $data['res'];
     // set the order's new status and update quantities if necessary
     Tienda::load('TiendaHelperOrder', 'helpers.order');
     $order = JTable::getInstance('Orders', 'TiendaTable');
     $order->load($data['vs']);
     if (count($errors)) {
         // if an error occurred
         $order->order_state_id = $this->params->get('failed_order_state', '10');
         // FAILED
     } else {
         $order->order_state_id = $this->params->get('payment_received_order_state', '17');
         // PAYMENT RECEIVED
         // do post payment actions
         $setOrderPaymentReceived = true;
         // send email
         $send_email = true;
     }
     // save the order
     if (!$order->save()) {
         $errors[] = $order->getError();
     }
     // save the orderpayment
     if (!$orderpayment->save()) {
         $errors[] = $orderpayment->getError();
     }
     if (!empty($setOrderPaymentReceived)) {
         $this->setOrderPaymentReceived($orderpayment->order_id);
     }
     if ($send_email) {
         // send notice of new order
         Tienda::load("TiendaHelperBase", 'helpers._base');
         $helper = TiendaHelperBase::getInstance('Email');
         $model = Tienda::getClass("TiendaModelOrders", "models.orders");
         $model->setId($orderpayment->order_id);
         $order = $model->getItem();
         $helper->sendEmailNotices($order, 'new_order');
     }
     if (empty($errors)) {
         $return = JText::_('TIENDA CARDPAY MESSAGE PAYMENT SUCCESS');
         return $return;
     }
     return count($errors) ? implode("\n", $errors) : '';
 }
Example #28
0
 /**
  * Returns a formatted path for the category
  * @param $id
  * @param $format
  * @return unknown_type
  */
 public static function getPathName($id, $format = 'flat', $linkSelf = false)
 {
     $name = '';
     if (empty($id)) {
         return $name;
     }
     if (isset($this) && is_a($this, 'TiendaHelperCategory')) {
         $helper = $this;
     } else {
         $helper = TiendaHelperBase::getInstance('Category');
     }
     if (empty($helper->categories[$id])) {
         JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
         $helper->categories[$id] = JTable::getInstance('Categories', 'TiendaTable');
         $helper->categories[$id]->load($id);
     }
     $item = $helper->categories[$id];
     if (empty($item->category_id)) {
         return $name;
     }
     $path = $item->getPath();
     switch ($format) {
         case "array":
             $name = array();
             foreach (@$path as $cat) {
                 $include_root = Tienda::getInstance()->get('include_root_pathway', false);
                 if (!$cat->isroot || $include_root) {
                     $pathway_object = new JObject();
                     $pathway_object->name = $cat->category_name;
                     $slug = $cat->category_alias ? ":{$cat->category_alias}" : "";
                     $link = "index.php?option=com_tienda&view=products&filter_category=" . $cat->category_id . $slug;
                     $pathway_object->link = $link;
                     $pathway_object->id = $cat->category_id;
                     $name[] = $pathway_object;
                 }
             }
             // add the item
             $pathway_object = new JObject();
             $pathway_object->name = $item->category_name;
             $slug = $item->category_alias ? ":{$item->category_alias}" : "";
             $link = "index.php?option=com_tienda&view=products&filter_category=" . $item->category_id . $slug;
             $pathway_object->link = $link;
             $pathway_object->id = $item->category_id;
             $name[] = $pathway_object;
             break;
         case "bullet":
             foreach (@$path as $cat) {
                 if (!$cat->isroot) {
                     $name .= '&bull;&nbsp;&nbsp;';
                     $name .= JText::_($cat->category_name);
                     $name .= "<br/>";
                 }
             }
             $name .= '&bull;&nbsp;&nbsp;';
             $name .= JText::_($item->category_name);
             break;
         case 'links':
             // get the root category
             JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
             $root = JTable::getInstance('Categories', 'TiendaTable')->getRoot();
             $root_itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($root->category_id, true);
             $include_root = Tienda::getInstance()->get('include_root_pathway', false);
             if ($include_root) {
                 $link = JRoute::_("index.php?option=com_tienda&view=products&filter_category=" . $root->category_id . "&Itemid=" . $root_itemid, false);
                 $name .= " <a href='{$link}'>" . JText::_('COM_TIENDA_ALL_CATEGORIES') . '</a> ';
             }
             foreach (@$path as $cat) {
                 if (!$cat->isroot) {
                     if (!($itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($cat->category_id, true))) {
                         $itemid = $root_itemid;
                     }
                     $slug = $cat->category_alias ? ":{$cat->category_alias}" : "";
                     $link = JRoute::_("index.php?option=com_tienda&view=products&filter_category=" . $cat->category_id . $slug . "&Itemid=" . $itemid, false);
                     if (!empty($name)) {
                         $name .= " > ";
                     }
                     $name .= " <a href='{$link}'>" . JText::_($cat->category_name) . '</a> ';
                 }
             }
             if (!empty($name)) {
                 $name .= " > ";
             }
             if ($linkSelf) {
                 if (!($itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($item->category_id, true))) {
                     $itemid = $root_itemid;
                 }
                 $slug = $item->category_alias ? ":{$item->category_alias}" : "";
                 $link = JRoute::_("index.php?option=com_tienda&view=products&filter_category=" . $item->category_id . $slug . "&Itemid=" . $itemid, false);
                 $name .= " <a href='{$link}'>" . JText::_($item->category_name) . '</a> ';
             } else {
                 $name .= JText::_($item->category_name);
             }
             break;
         default:
             foreach (@$path as $cat) {
                 if (!$cat->isroot) {
                     $name .= " / ";
                     $name .= JText::_($cat->category_name);
                 }
             }
             $name .= " / ";
             $name .= JText::_($item->category_name);
             break;
     }
     return $name;
 }
Example #29
0
    		<td style="text-align: center;">
    			<input id="createproductfileserver_name" name="createproductfileserver_name" value="" size="40" />
    		</td>
            <td style="text-align: center;">
                <?php 
echo TiendaSelect::btbooleanlist('createproductfileserver_purchaserequired', '', '');
?>
            </td>
    		<td style="text-align: center;">
    		    <?php 
echo TiendaSelect::btbooleanlist('createproductfileserver_enabled', '', '');
?>
    		</td>
            <td style="text-align: center;">
                <?php 
$helper = Tienda::getClass('TiendaHelperProduct', 'helpers.product');
$path = $helper->getFilePath($row->product_id);
$files = $helper->getServerFiles($path);
$list = array();
foreach (@$files as $file) {
    $list[] = TiendaSelect::option($file, $file);
}
echo JHTMLSelect::genericlist($list, 'createproductfileserver_file');
?>
            </td>
            <td style="text-align: center;">
                <input type="text" name="createproductfileserver_max_download" id="createproductfileserver_max_download" value="-1" size="10" maxlength="250" />
            </td>
            
    	</tr>
    	</tbody>
Example #30
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;
 }