Example #1
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 #2
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 #3
0
 /**
  * Saves the order to the database
  *
  * @param $values
  * @return unknown_type
  */
 function saveOrder($values, $user_id, $ajax = false)
 {
     $error = false;
     $guest = $user_id < Tienda::getGuestIdStart();
     $order = $this->_order;
     // a TableOrders object (see constructor)
     $order->_adjustCredits = true;
     // this is not a POS order, so adjust the user's credits (if any used)
     $order->bind($values);
     $order->user_id = $user_id;
     $order->ip_address = $_SERVER['REMOTE_ADDR'];
     $this->setAddresses($values, false, $ajax);
     // set the shipping method
     if (@$values['shippingrequired'] || !empty($values['shipping_plugin'])) {
         $order->shipping = new JObject();
         $order->shipping->shipping_price = $values['shipping_price'];
         $order->shipping->shipping_extra = $values['shipping_extra'];
         $order->shipping->shipping_name = $values['shipping_name'];
         $order->shipping->shipping_tax = $values['shipping_tax'];
     }
     // Store the text verion of the currency for order integrity
     Tienda::load('TiendaHelperOrder', 'helpers.order');
     $order->order_currency = TiendaHelperOrder::currencyToParameters($order->currency_id);
     //get the items and add them to the order
     Tienda::load('TiendaHelperCarts', 'helpers.carts');
     //we dont need to add items in the order if onepage checkout since its already added in the shipping validation
     if (!$this->onepage_checkout) {
         $reviewitems = TiendaHelperCarts::getProductsInfo();
         foreach ($reviewitems as $reviewitem) {
             $order->addItem($reviewitem);
         }
     }
     $this->addCoupons($values);
     $order->order_state_id = $this->initial_order_state;
     $order->calculateTotals();
     $order->getShippingTotal();
     $order->getInvoiceNumber();
     $model = JModel::getInstance('Orders', 'TiendaModel');
     //TODO: Do Something with Payment Infomation
     if ($order->save()) {
         $model->setId($order->order_id);
         // save the order items
         if (!$this->saveOrderItems()) {
             // TODO What to do if saving order items fails?
             $error = true;
         }
         // save the order vendors
         if (!$this->saveOrderVendors()) {
             // TODO What to do if saving order vendors fails?
             $error = true;
         }
         // save the order info
         if (!$this->saveOrderInfo()) {
             // TODO What to do if saving order info fails?
             $error = true;
         }
         // save the order history
         if (!$this->saveOrderHistory()) {
             // TODO What to do if saving order history fails?
             $error = true;
         }
         // save the order taxes
         if (!$this->saveOrderTaxes()) {
             // TODO What to do if saving order taxes fails?
             $error = true;
         }
         // save the order shipping info
         if (isset($order->shipping) && !$this->saveOrderShippings($values)) {
             // TODO What to do if saving order shippings fails?
             $error = true;
         }
         // save the order coupons
         if (!$this->saveOrderCoupons()) {
             // TODO What to do if saving order coupons fails?
             $error = true;
         }
         $model->clearCache();
     }
     if ($error) {
         return false;
     }
     return true;
 }
Example #4
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 #5
0
 /**
  * This method for after an orderpayment has been received when the admin click on the
  * that performs acts such as:
  * enabling file downloads
  *
  * @param $order_id
  * @return unknown_type
  */
 public static function doCompletedOrderTasks($order_id)
 {
     $errors = array();
     $error = false;
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $order = JTable::getInstance('Orders', 'TiendaTable');
     $order->load($order_id);
     if (empty($order->order_id)) {
         // TODO we must make sure this class is always instantiated
         $this->setError(JText::_('COM_TIENDA_INVALID_ORDER_ID'));
         return false;
     }
     // Fire an doCompletedOrderTasks event
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('doCompletedOrderTasks', array($order_id));
     // 0. Enable One-Time Purchase Subscriptions
     TiendaHelperOrder::enableNonRecurringSubscriptions($order_id);
     // 1. Update quantities
     TiendaHelperOrder::updateProductQuantities($order_id, '-');
     // 2. remove items from cart
     Tienda::load('TiendaHelperCarts', 'helpers.carts');
     TiendaHelperCarts::removeOrderItems($order_id);
     // 3. add productfiles to product downloads
     TiendaHelperOrder::enableProductDownloads($order_id);
     // 4. do SQL queries
     $helper = TiendaHelperBase::getInstance('Sql');
     $helper->processOrder($order_id);
     // register commission if amigos is installed
     $helper = TiendaHelperBase::getInstance('Amigos');
     $helper->createCommission($order_id);
     // change ticket limits if billets is installed
     $helper = TiendaHelperBase::getInstance('Billets');
     $helper->processOrder($order_id);
     // add to JUGA Groups if JUGA installed
     $helper = TiendaHelperBase::getInstance('Juga');
     $helper->processOrder($order_id);
     // change core ACL if set
     $helper = TiendaHelperBase::getInstance('User');
     $helper->processOrder($order_id);
     // do Ambra Subscriptions Integration processes
     $helper = TiendaHelperBase::getInstance('Ambrasubs');
     $helper->processOrder($order_id);
     // increase the hit counts for coupons in the order
     $helper = TiendaHelperBase::getInstance('Coupon');
     $helper->processOrder($order_id);
     if ($error) {
         $this->setError(implode('<br/>', $errors));
         return false;
     } else {
         $order->completed_tasks = '1';
         $order->store();
         return true;
     }
 }
 /**
  *  this is updating the transaction id with the Google Order id
  *
  */
 function _saveTransaction($data, $error = '')
 {
     $errors = array();
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable');
     $oredrPaymentId = $data['shopping-cart']['merchant-private-data']['orderPaymentId']['VALUE'];
     $orderpayment->load($oredrPaymentId);
     if (empty($orderpayment->orderpayment_id)) {
         $errors[] = JText::_('COM_TIENDA_GOOGLECHECKOUT_CHECKOUT_INVALID_ORDERPAYMENTID');
         return count($errors) ? implode("\n", $errors) : '';
     }
     $orderpayment->transaction_id = $data['google-order-number']['VALUE'];
     // update the orderpayment
     if (!$orderpayment->save()) {
         $errors[] = $orderpayment->getError();
     }
     // 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 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);
     // send email
     $send_email = true;
     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 #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
 /**
  * This method can be executed by a payment plugin after a succesful payment
  * to perform acts such as enabling file downloads, removing items from cart,
  * updating product quantities, etc
  * 
  * @param unknown_type $order_id
  * @return unknown_type
  */
 function setOrderPaymentReceived($order_id)
 {
     Tienda::load('TiendaHelperOrder', 'helpers.order');
     TiendaHelperOrder::setOrderPaymentReceived($order_id);
 }
Example #9
0
 /**
  * _lifetime function.
  *
  * @access private
  * @return void
  */
 function _lifetime()
 {
     $database = JFactory::getDBO();
     $today = TiendaHelperBase::getToday();
     Tienda::load('TiendaHelperOrder', 'helpers.order');
     $firstsale_date = TiendaHelperOrder::getDateMarginalOrder($this->getStatesCSV(), 'ASC');
     $lastsale_date = TiendaHelperOrder::getDateMarginalOrder($this->getStatesCSV(), 'DESC');
     $return = $this->_getDateDb($firstsale_date, $lastsale_date);
     $days = $return->days_in_business > 0 ? $return->days_in_business : 1;
     $return->average_daily = $return->num / $days;
     return $return;
 }
Example #10
0
    ?>
        <?php 
}
?>
	</div>
		
    <div id="order_info">
        <h3><?php 
echo JText::_('COM_TIENDA_ORDER_INFORMATION');
?>
</h3>
        <strong><?php 
echo JText::_('COM_TIENDA_ORDER_ID');
?>
</strong>: <?php 
echo TiendaHelperOrder::displayOrderNumber($row);
?>
<br/>
        <strong><?php 
echo JText::_('COM_TIENDA_DATE');
?>
</strong>: <?php 
echo JHTML::_('date', $row->created_date, Tienda::getInstance()->get('date_format'));
?>
<br/>
        <strong><?php 
echo JText::_('COM_TIENDA_STATUS');
?>
</strong>: <?php 
echo @$row->order_state_name;
?>
Example #11
0
 function saveOrder($values)
 {
     $session = JFactory::getSession();
     $user_id = $session->get('user_id', '', 'tienda_pos');
     $error = false;
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $order = JTable::getInstance('Orders', 'TiendaTable');
     $order->bind($values);
     $order->user_id = $user_id;
     $order->ip_address = $_SERVER['REMOTE_ADDR'];
     $this->setAddresses($order, $values);
     $session = JFactory::getSession();
     // set the shipping method
     if ($values['shippingrequired']) {
         $order->shipping = new JObject();
         $order->shipping->shipping_price = $session->get('shipping_price', '', 'tienda_pos');
         $order->shipping->shipping_extra = $session->get('shipping_extra', '', 'tienda_pos');
         $order->shipping->shipping_name = $session->get('shipping_name', '', 'tienda_pos');
         $order->shipping->shipping_tax = $session->get('shipping_tax', '', 'tienda_pos');
     }
     // Store the text verion of the currency for order integrity
     Tienda::load('TiendaHelperOrder', 'helpers.order');
     $order->order_currency = TiendaHelperOrder::currencyToParameters($order->currency_id);
     $reviewitems = $this->getProductsInfo();
     foreach ($reviewitems as $reviewitem) {
         $order->addItem($reviewitem);
     }
     // get all coupons and add them to the order
     $coupons_enabled = Tienda::getInstance()->get('coupons_enabled');
     $mult_enabled = Tienda::getInstance()->get('multiple_usercoupons_enabled');
     if (!empty($values['coupons']) && $coupons_enabled) {
         foreach ($values['coupons'] as $coupon_id) {
             $coupon = JTable::getInstance('Coupons', 'TiendaTable');
             $coupon->load(array('coupon_id' => $coupon_id));
             $order->addCoupon($coupon);
             if (empty($mult_enabled)) {
                 // this prevents Firebug users from adding multiple coupons to orders
                 break;
             }
         }
     }
     $order->order_state_id = 15;
     $order->calculateTotals();
     $order->getShippingTotal();
     $order->getInvoiceNumber();
     $model = DSCModel::getInstance('Orders', 'TiendaModel');
     if ($order->save()) {
         $model->setId($order->order_id);
         // save the order items
         if (!$this->saveOrderItems($order)) {
             // TODO What to do if saving order items fails?
             $error = true;
         }
         // save the order vendors
         if (!$this->saveOrderVendors($order)) {
             // TODO What to do if saving order vendors fails?
             $error = true;
         }
         // save the order info
         if (!$this->saveOrderInfo($order)) {
             // TODO What to do if saving order info fails?
             $error = true;
         }
         // save the order history
         if (!$this->saveOrderHistory($order)) {
             // TODO What to do if saving order history fails?
             $error = true;
         }
         // save the order taxes
         if (!$this->saveOrderTaxes($order)) {
             // TODO What to do if saving order taxes fails?
             $error = true;
         }
         // save the order shipping info
         if (!$this->saveOrderShippings($order)) {
             // TODO What to do if saving order shippings fails?
             $error = true;
         }
         // save the order coupons
         if (!$this->saveOrderCoupons($order)) {
             // TODO What to do if saving order coupons fails?
             $error = true;
         }
         $model->clearCache();
     }
     return $order;
 }
Example #12
0
 public function prepare($values, $options = array(), &$order = null)
 {
     if (empty($order)) {
         $order = $this->getTable();
     }
     $this->_order =& $order;
     $this->_values = $values;
     $this->_options = $options;
     if (empty($options['skip_adjust_credits'])) {
         $order->_adjustCredits = true;
         // this is not a POS order, so adjust the user's credits (if any used)
     }
     $order->bind($values);
     $order->user_id = $values['user_id'];
     $order->ip_address = $values['ip_address'];
     //$_SERVER['REMOTE_ADDR'];
     // set the currency
     if (empty($values['currency_id'])) {
         Tienda::load('TiendaHelperCurrency', 'helpers.currency');
         $order->currency_id = TiendaHelperCurrency::getCurrentCurrency();
     }
     // Store the text verion of the currency for order integrity
     Tienda::load('TiendaHelperOrder', 'helpers.order');
     $order->order_currency = TiendaHelperOrder::currencyToParameters($order->currency_id);
     $saveAddressesToDB = empty($options["save_addresses"]) ? false : true;
     $this->setAddresses($values, $saveAddressesToDB);
     // set the shipping method
     if (@$values['shippingrequired'] || !empty($values['shipping_plugin'])) {
         $order->shipping = new JObject();
         $order->shipping->shipping_price = $values['shipping_price'];
         $order->shipping->shipping_extra = $values['shipping_extra'];
         $order->shipping->shipping_name = $values['shipping_name'];
         $order->shipping->shipping_tax = $values['shipping_tax'];
     }
     if (empty($options['skip_add_items'])) {
         //get the items from the current user's cart and add them to the order
         Tienda::load('TiendaHelperCarts', 'helpers.carts');
         $reviewitems = TiendaHelperCarts::getProductsInfo();
         foreach ($reviewitems as $reviewitem) {
             $order->addItem($reviewitem);
         }
     }
     if (empty($options['skip_add_coupons'])) {
         $this->addCoupons($values);
     }
     if (empty($options['skip_add_credit']) && !empty($values['order_credit'])) {
         $order->addCredit($values['order_credit']);
     }
     $order->order_state_id = empty($values['orderstate_id']) ? $this->initial_order_state : $values['orderstate_id'];
     $order->calculateTotals();
     $order->getShippingTotal();
     $order->getInvoiceNumber();
     return $order;
 }
Example #13
0
 public function getStatIntervalValues($stats_interval)
 {
     $this->setStatesCSV();
     $interval = new stdClass();
     switch ($stats_interval) {
         case "annually":
             $firstsale_date = TiendaHelperOrder::getDateMarginalOrder($this->getStatesCSV(), 'ASC');
             $interval->date_from = date('Y-01-01 00:00:00', strtotime($firstsale_date));
             $interval->date_to = 'NOW';
             $interval->next_date = '+1 year';
             $interval->step = '1';
             $interval->pointinterval = 365 * 24 * 3600 * 1000;
             // one year
             $interval->index_format = 'Y-01-01';
             $interval->current_date_format = 'Y-01-01';
             $interval->end_date_format = 'Y-12-31';
             $interval->hour_format = '0';
             break;
         case "today":
             $interval->date_from = date('Y-m-d 00:00:00', strtotime('NOW'));
             $interval->date_to = date('Y-m-d 23:59:59', strtotime('NOW'));
             $interval->next_date = '+1 hour';
             $interval->step = 1;
             $interval->pointinterval = 3600 * 1000;
             // one hour
             $interval->index_format = 'Y-m-d H:00:00';
             $interval->current_date_format = 'Y-m-d H:00:00';
             $interval->end_date_format = 'Y-m-d 23:59:59';
             $interval->hour_format = 'H';
             break;
         case "yesterday":
             $interval->date_from = date('Y-m-d 00:00:00', strtotime('yesterday'));
             $interval->date_to = date('Y-m-d 23:59:59', strtotime('yesterday'));
             $interval->next_date = '+1 hour';
             $interval->step = 1;
             $interval->pointinterval = 3600 * 1000;
             // one hour
             $interval->index_format = 'Y-m-d H:00:00';
             $interval->current_date_format = 'Y-m-d H:00:00';
             $interval->end_date_format = 'Y-m-d 23:59:59';
             $interval->hour_format = 'H';
             break;
         case "ytd":
             $interval->date_from = date('Y', strtotime('NOW')) . '-01-01';
             $interval->date_to = 'NOW';
             $interval->next_date = '+1 month';
             $interval->step = 1;
             $interval->pointinterval = 30.25 * 24 * 3600 * 1000;
             // one month
             $interval->index_format = 'Y-m-01';
             $interval->current_date_format = 'Y-m-d';
             $interval->end_date_format = 'Y-m-d';
             $interval->hour_format = '0';
             break;
         case "last_seven":
             $interval->date_from = 'NOW -7 days';
             $interval->date_to = 'NOW';
             $interval->next_date = '+1 day';
             $interval->step = '1';
             $interval->pointinterval = 24 * 3600 * 1000;
             // one day
             $interval->index_format = 'Y-m-d';
             $interval->current_date_format = 'Y-m-d';
             $interval->end_date_format = 'Y-m-d';
             $interval->hour_format = '0';
             break;
         case "last_thirty":
         default:
             $interval->date_from = 'NOW -30 days';
             $interval->date_to = 'NOW';
             $interval->next_date = '+1 day';
             $interval->step = '7';
             $interval->pointinterval = 24 * 3600 * 1000;
             // one day
             $interval->index_format = 'Y-m-d';
             $interval->current_date_format = 'Y-m-d';
             $interval->end_date_format = 'Y-m-d';
             $interval->hour_format = '0';
             break;
     }
     return $interval;
 }
Example #14
0
 /**
  * This method is updating the all orders on the basis of the action
  * @return void
  */
 function updatebatch()
 {
     $model = $this->getModel($this->get('suffix'));
     // Get the list of selected items and their selected params
     $cids = JRequest::getVar('cid', array(0), 'post', 'array');
     $sendMails = JRequest::getVar('new_orderstate_notify', array(0), 'post', 'array');
     $completeTasks = JRequest::getVar('completed_tasks', array(0), 'post', 'array');
     $states = JRequest::getVar('new_orderstate_id', array(0), 'post', 'array');
     $comments = JRequest::getVar('new_orderstate_comments', array(0), 'post', 'array');
     // for the updation
     $counter = 0;
     foreach (@$cids as $orderId) {
         $row = $model->getTable();
         $row->load($orderId);
         $row->order_state_id = $states[$counter];
         $completed_tasks = $completeTasks[$orderId];
         $is_notify = 0;
         if ($completed_tasks == "on" && empty($row->completed_tasks)) {
             Tienda::load('TiendaHelperOrder', 'helpers.order');
             TiendaHelperOrder::doCompletedOrderTasks($row->order_id);
             $row->completed_tasks = 1;
         }
         // saving the row
         if ($row->save()) {
             $model->setId($row->order_id);
             $this->messagetype = 'message';
             $this->message = JText::_('COM_TIENDA_ORDER_SAVED');
             $history = JTable::getInstance('OrderHistory', 'TiendaTable');
             $history->order_id = $row->order_id;
             $history->order_state_id = $row->order_state_id;
             if ($sendMails[$orderId] == "on") {
                 $is_notify = 1;
             }
             $history->notify_customer = $is_notify;
             $history->comments = $comments[$counter];
             if (!$history->save()) {
                 $this->setError($history->getError());
                 $this->messagetype = 'notice';
                 $this->message .= " :: " . JText::_('COM_TIENDA_ORDERHISTORY_SAVE_FAILED');
             }
             $dispatcher = JDispatcher::getInstance();
             $dispatcher->trigger('onAfterUpdateStatus' . $this->get('suffix'), array($row));
         } else {
             $this->messagetype = 'notice';
             $this->message = JText::_('COM_TIENDA_SAVE_FAILED') . " - " . $row->getError();
         }
         $counter++;
     }
     $model->clearCache();
     $redirect = "index.php?option=com_tienda";
     $redirect .= '&view=' . $this->get('suffix');
     $redirect = JRoute::_($redirect, false);
     $this->setRedirect($redirect, $this->message, $this->messagetype);
 }
Example #15
0
 /**
  * (non-PHPdoc)
  * @see tienda/site/TiendaController#view()
  */
 function printOrder()
 {
     // if the user cannot view order, fail
     $model = $this->getModel($this->get('suffix'));
     $model->getId();
     $order = $model->getTable('orders');
     $order->load($model->getId());
     $row = $model->getItem();
     $row->order_ships = $order->order_ships;
     $orderitems = $order->getItems();
     $user_id = JFactory::getUser()->id;
     if ($row->user_id > 0) {
         if (empty($user_id) || $user_id != $row->user_id) {
             $this->messagetype = 'notice';
             $this->message = JText::_('COM_TIENDA_INVALID_ORDER');
             $redirect = "index.php?option=com_tienda&view=" . $this->get('suffix');
             $redirect = JRoute::_($redirect, false);
             $this->setRedirect($redirect, $this->message, $this->messagetype);
             return;
         }
     } else {
         $hash = JRequest::getString('h', '');
         if ($row->order_hash != $hash) {
             $this->messagetype = 'notice';
             $this->message = JText::_('COM_TIENDA_INVALID_ORDER');
             $redirect = "index.php?option=com_tienda&view=" . $this->get('suffix');
             $redirect = JRoute::_($redirect, false);
             $this->setRedirect($redirect, $this->message, $this->messagetype);
             return;
         }
     }
     Tienda::load('TiendaUrl', 'library.url');
     $view = $this->getView('orders', 'html');
     $view->set('_controller', 'orders');
     $view->set('_view', 'orders');
     $view->set('_doTask', true);
     $view->set('hidemenu', true);
     $view->setModel($model, true);
     $config = Tienda::getInstance();
     $show_tax = $config->get('display_prices_with_tax');
     if ($show_tax) {
         $order->order_subtotal += $order->order_tax;
     }
     //START onDisplayOrderItem: trigger plugins for extra orderitem information
     if (!empty($orderitems)) {
         Tienda::load('TiendaHelperOrder', 'helpers.order');
         $onDisplayOrderItem = TiendaHelperOrder::onDisplayOrderItems($orderitems);
         $view->assign('onDisplayOrderItem', $onDisplayOrderItem);
     }
     foreach ($orderitems as $item) {
         if ($show_tax) {
             $item->orderitem_price += $item->orderitem_tax / $item->orderitem_quantity;
         }
     }
     //END onDisplayOrderItem
     $view->assign('show_tax', $show_tax);
     $view->assign('using_default_geozone', false);
     $view->assign('order', $order);
     $view->setLayout('print');
     $view->display();
 }