Example #1
0
 /**
  * Processes a new order
  * 
  * @param $order_id
  * @return unknown_type
  */
 public function processOrder($order_id)
 {
     // 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);
     }
     // find the products in the order that are integrated
     foreach ($order->orderitems as $orderitem) {
         $model = JModel::getInstance('Products', 'TiendaModel');
         $product = $model->getTable();
         $product->load($orderitem->product_id);
         $this->_product = $product;
         $this->_orderitem = $orderitem;
         if (!empty($product->product_sql)) {
             $this->processSQL($product->product_sql);
         }
     }
 }
Example #2
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 #3
0
 function store($updateNulls = false)
 {
     // add hash to orders which are placed by guests
     if (!$this->order_id && !strlen($this->order_hash) && $this->user_id < Tienda::getGuestIdStart()) {
         Tienda::load('TiendaHelperOrder', 'helpers.order');
         $this->order_hash = TiendaHelperOrder::getHashInvoice($this);
     }
     return parent::store($updateNulls);
 }
Example #4
0
 /**
  * Checks that an email is valid
  * @return unknown_type
  */
 function checkEmail()
 {
     Tienda::load('TiendaHelperUser', 'helpers.user');
     $checker = TiendaHelperUser::getInstance('User', 'TiendaHelper');
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $helper = TiendaHelperBase::getInstance();
     $response = array();
     $response['msg'] = '';
     $response['error'] = '0';
     // get elements from post
     $elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', JRequest::getVar('elements', '', 'post', 'string', 'string')));
     // convert elements to array that can be binded
     $values = $helper->elementsToArray($elements);
     $email = $values['email_address'];
     if (empty($email)) {
         $response['msg'] = $helper->validationMessage("COM_TIENDA_EMAIL_CANNOT_BE_EMPTY", 'fail');
         $response['error'] = '1';
         echo json_encode($response);
         return;
     }
     $message = "";
     if (!$checker->isEmailAddress($email)) {
         $message .= $helper->validationMessage("COM_TIENDA_EMAIL_INVALID", 'fail');
         $response['error'] = '1';
     }
     if ($checker->emailExists($email)) {
         $user_id = $this->user->id;
         $user_email = $checker->getBasicInfo($user_id)->email;
         if ($user_id && $user_id > Tienda::getGuestIdStart()) {
             if ($user_email != $email) {
                 $message .= $helper->validationMessage("COM_TIENDA_EMAIL_ALREADY_REGISTERED", 'fail');
                 $response['error'] = '1';
             }
         } else {
             $message .= $helper->validationMessage("COM_TIENDA_EMAIL_ALREADY_REGISTERED", 'fail');
             $response['error'] = '1';
         }
     }
     if ($response['error'] == '0') {
         // no error
         $message .= $helper->validationMessage('COM_TIENDA_VALID_EMAIL', 'success');
     }
     $response['msg'] = $message;
     echo json_encode($response);
     return;
 }
Example #5
0
<?php

defined('_JEXEC') or die('Restricted access');
JHTML::_('script', 'tienda.js', 'media/com_tienda/js/');
$form = @$this->form;
$row = @$this->row;
$order = @$this->order;
$items = @$order->getItems();
$histories = @$row->orderhistory ? @$row->orderhistory : array();
$config = Tienda::getInstance();
$guest = $row->user_id < Tienda::getGuestIdStart();
?>


<form action="<?php 
echo JRoute::_(@$form['action']);
?>
" method="post" class="adminform" name="adminForm" enctype="multipart/form-data" >

    <?php 
// fire plugin event here to enable extending the form
JDispatcher::getInstance()->trigger('onBeforeDisplayOrderPrint', array($row));
?>

    <table style="width: 100%;">
    <tr>
    	<td colspan="2" style="vertical-align:top;">
    	
    	 <fieldset>
            <legend><?php 
echo JText::_('COM_TIENDA_SHOP_INFORMATION');
Example #6
0
 /**
  * Method which returns the next guest user account ID in the system
  * (starts off with -11 => reserve 0 ... -10 for later use)
  * 
  * @return Guest user account ID
  */
 public function getNextGuestUserId()
 {
     $db = JFactory::getDbo();
     Tienda::load('TiendaQuery', 'library.query');
     $q = new TiendaQuery();
     $start_id = Tienda::getGuestIdStart();
     $q->select('min( tbl.user_id)');
     $q->from('#__tienda_userinfo tbl');
     $q->where('tbl.user_id < ' . $start_id);
     $db->setQuery((string) $q);
     $res = $db->loadResult();
     if ($res === null) {
         // no guest account in system
         return $start_id - 1;
     } else {
         return $res - 1;
     }
     // the last guest account id -1
 }
Example #7
0
 /**
  * Returns 
  * 
  * @param object
  * @param mixed Boolean
  * @param mixed Boolean
  * @return array
  */
 private function getEmailContent($data, $type = 'order')
 {
     $mainframe = JFactory::getApplication();
     $type = strtolower($type);
     $lang = JFactory::getLanguage();
     $lang->load('com_tienda', JPATH_ADMINISTRATOR);
     $return = new stdClass();
     $return->body = '';
     $return->subject = '';
     // get config settings
     $config = TiendaConfig::getInstance();
     $sitename = $config->get('sitename', $mainframe->getCfg('sitename'));
     $siteurl = $config->get('siteurl', JURI::root());
     // get the placeholders array here so the switch statement can add to it
     $placeholders = $this->getPlaceholderDefaults();
     switch ($type) {
         case "subscription_expiring":
             $return->subject = JText::_('COM_TIENDA_EMAIL_EXPIRING_SUBSCRIPTION_SUBJECT');
             $return->body = JText::_('COM_TIENDA_EMAIL_EXPIRING_SUBSCRIPTION_BODY');
             if ($this->use_html) {
                 $return->body = nl2br($return->body);
             }
             $placeholders['user.name'] = $data->user_name;
             $placeholders['product.name'] = $data->product_name;
             break;
         case "subscription_expired":
             $return->subject = JText::_('COM_TIENDA_EMAIL_EXPIRED_SUBSCRIPTION_SUBJECT');
             $return->body = JText::_('COM_TIENDA_EMAIL_EXPIRED_SUBSCRIPTION_BODY');
             if ($this->use_html) {
                 $return->body = nl2br($return->body);
             }
             $placeholders['user.name'] = $data->user_name;
             $placeholders['product.name'] = $data->product_name;
             break;
         case "subscription_new":
         case "new_subscription":
         case "subscription":
             $user_name = JText::_('COM_TIENDA_GUEST');
             if ($data->user_id > 0) {
                 $user = JUser::getInstance($data->user_id);
                 $user_name = $user->name;
             }
             if ($data->user_id < Tienda::getGuestIdStart()) {
                 $link = JURI::root() . "index.php?option=com_tienda&view=orders&task=view&id=" . $data->order_id . '&h=' . $data->order_hash;
             } else {
                 $link = JURI::root() . "index.php?option=com_tienda&view=orders&task=view&id=" . $data->order_id;
             }
             $link = JRoute::_($link, false);
             $link = "<a href='{$link}'>" . $link . "</a>";
             if (count($data->history) == 1) {
                 // new order
                 $return->subject = sprintf(JText::_('COM_TIENDA_EMAIL_NEW_ORDER_SUBJECT'), $data->order_id);
                 // set the email body
                 $text = sprintf(JText::_('COM_TIENDA_EMAIL_DEAR'), $user_name) . ",\n\n";
                 $text .= JText::_('COM_TIENDA_EMAIL_THANKS_NEW_SUBSCRIPTION') . "\n\n";
                 $text .= sprintf(JText::_('COM_TIENDA_EMAIL_CHECK'), $link) . "\n\n";
                 $text .= JText::_('COM_TIENDA_EMAIL_RECEIPT_FOLLOWS') . "\n\n";
                 if ($this->use_html) {
                     $text = nl2br($text);
                 }
                 // get the order body
                 Tienda::load('TiendaHelperOrder', 'helpers.order');
                 $text .= TiendaHelperOrder::getOrderHtmlForEmail($data->order_id);
             } else {
                 // Status Change
                 $return->subject = JText::_('COM_TIENDA_EMAIL_SUBSCRIPTION_STATUS_CHANGE');
                 $last_history = count($data->history) - 1;
                 $text = sprintf(JText::_('COM_TIENDA_EMAIL_DEAR'), $user_name) . ",\n\n";
                 $text .= sprintf(JText::_('COM_TIENDA_EMAIL_ORDER_UPDATED'), $data->order_id);
                 if (!empty($data->history[$last_history]->comments)) {
                     $text .= sprintf(JText::_('COM_TIENDA_EMAIL_ADDITIONAL_COMMENTS'), $data->history[$last_history]->comments);
                 }
                 $text .= sprintf(JText::_('COM_TIENDA_EMAIL_CHECK'), $link) . "\n\n";
                 if ($this->use_html) {
                     $text = nl2br($text);
                 }
             }
             $return->body = $text;
             $placeholders['user.name'] = $user_name;
             break;
         case "new_order":
         case "order":
         default:
             $user_name = JText::_('COM_TIENDA_GUEST');
             if ($data->user_id > 0) {
                 $user = JUser::getInstance($data->user_id);
                 $user_name = $user->name;
             }
             if ($data->user_id < Tienda::getGuestIdStart()) {
                 $link = JURI::root() . "index.php?option=com_tienda&view=orders&task=view&id=" . $data->order_id . '&h=' . $data->order_hash;
             } else {
                 $link = JURI::root() . "index.php?option=com_tienda&view=orders&task=view&id=" . $data->order_id;
             }
             $link = JRoute::_($link, false);
             $link = "<a href='{$link}'>" . $link . "</a>";
             if ($type == 'new_order') {
                 // new order
                 $return->subject = sprintf(JText::_('COM_TIENDA_EMAIL_NEW_ORDER_SUBJECT'), $data->order_id);
                 // set the email body
                 $text = sprintf(JText::_('COM_TIENDA_EMAIL_DEAR'), $user_name) . ",\n\n";
                 $text .= JText::_('COM_TIENDA_EMAIL_THANKS_NEW_ORDER') . "\n\n";
                 $text .= sprintf(JText::_('COM_TIENDA_EMAIL_CHECK'), $link) . "\n\n";
                 $text .= JText::_('COM_TIENDA_EMAIL_RECEIPT_FOLLOWS') . "\n\n";
                 if ($this->use_html) {
                     $text = nl2br($text);
                 }
                 // get the order body
                 Tienda::load('TiendaHelperOrder', 'helpers.order');
                 $text .= TiendaHelperOrder::getOrderHtmlForEmail($data->order_id);
             } else {
                 // Status Change
                 $return->subject = JText::_('COM_TIENDA_EMAIL_ORDER_STATUS_CHANGE');
                 $last_history = count($data->orderhistory) - 1;
                 $text = sprintf(JText::_('COM_TIENDA_EMAIL_DEAR'), $user_name) . ",\n\n";
                 $text .= sprintf(JText::_('COM_TIENDA_EMAIL_ORDER_UPDATED'), $data->order_id);
                 $text .= JText::_('COM_TIENDA_EMAIL_NEW_STATUS') . " " . $data->orderhistory[$last_history]->order_state_name . "\n\n";
                 if (!empty($data->orderhistory[$last_history]->comments)) {
                     $text .= sprintf(JText::_('COM_TIENDA_EMAIL_ADDITIONAL_COMMENTS'), $data->orderhistory[$last_history]->comments);
                 }
                 $text .= sprintf(JText::_('COM_TIENDA_EMAIL_CHECK'), $link) . "\n\n";
                 if ($this->use_html) {
                     $text = nl2br($text);
                 }
             }
             $return->body = $text;
             $placeholders['user.name'] = $user_name;
             break;
     }
     // replace placeholders in language strings - great idea, Oleg
     $return->subject = $this->replacePlaceholders($return->subject, $placeholders);
     $return->body = $this->replacePlaceholders($return->body, $placeholders);
     return $return;
 }
Example #8
0
 public function getList($refresh = false)
 {
     if (empty($this->_list)) {
         Tienda::load('TiendaHelperBase', 'helpers._base');
         $list = parent::getList($refresh);
         // If no item in the list, return an array()
         if (empty($list)) {
             return array();
         }
         $amigos = TiendaHelperBase::getInstance('Amigos');
         $currency_helper = TiendaHelperBase::getInstance('Currency');
         foreach (@$list as $item) {
             if ($item->user_id < Tienda::getGuestIdStart()) {
                 if (strlen($item->billing_first_name) || strlen($item->billing_last_name)) {
                     $item->user_name = JText::_('COM_TIENDA_GUEST') . ' - ' . $item->billing_first_name . ' ' . $item->billing_last_name;
                 } else {
                     $item->user_name = JText::_('COM_TIENDA_GUEST') . ' - ' . $item->userinfo_email;
                 }
             }
             $item->link = 'index.php?option=com_tienda&controller=orders&view=orders&task=edit&id=' . $item->order_id;
             $item->link_view = 'index.php?option=com_tienda&view=orders&task=view&id=' . $item->order_id;
             // retrieve the order's currency
             // this loads the currency, using the FK is it is the same of the
             // currency used in the order, or the DSCParameter currency of the order otherwise
             $order_currency = new DSCParameter($item->order_currency);
             $order_currency = $order_currency->toArray();
             //JModel::addIncludePath( JPATH_ADMINISTRATOR.'/components/com_tienda/models' );
             //$cmodel = JModel::getInstance( 'Currencies', 'TiendaModel' );
             //$cmodel->setId($item->currency_id);
             $item->currency = $currency_helper->load($item->currency_id);
             // if the order currency is not the same as it was during the order
             if (!empty($item->currency) && !empty($order_currency['currency_code']) && $item->currency->currency_code != $order_currency['currency_code']) {
                 // overwrite it with the original one
                 foreach (@$order_currency as $k => $v) {
                     $item->currency->{$k} = $v;
                 }
             }
             // has a commission?
             if ($amigos->isInstalled()) {
                 $item->commissions = $amigos->getCommissions($item->order_id);
             }
         }
         $this->_list = $list;
     }
     return $this->_list;
 }
Example #9
0
?>
</div>
					<?php 
echo @$this->pagination->getPagesLinks();
?>
				</td>
			</tr>
		</tfoot>
        <tbody>
		<?php 
$i = 0;
$k = 0;
?>
        <?php 
foreach (@$items as $item) {
    $guest = $item->user_id < Tienda::getGuestIdStart();
    ?>
            <tr class='row<?php 
    echo $k;
    ?>
'>
				<td align="center">
					<?php 
    echo $i + 1;
    ?>
				</td>
				<td style="text-align: center;">
					<?php 
    echo TiendaGrid::checkedout($item, $i, 'order_id');
    ?>
				</td>