Exemple #1
0
 /**
  * Validates the credit amount and applies it to the order
  * @return unknown_type
  */
 function validateApplyCredit()
 {
     JLoader::import('com_tienda.library.json', JPATH_ADMINISTRATOR . '/components');
     $elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', JRequest::getVar('elements', '', 'post', 'string')));
     // convert elements to array that can be binded
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $helper = TiendaHelperBase::getInstance();
     $values = $helper->elementsToArray($elements);
     $user_id = $this->user->id;
     $apply_credit_amount = (double) JRequest::getVar('apply_credit_amount', '');
     $response = array();
     $response['msg'] = '';
     $response['error'] = '';
     // is the credit amount valid (i.e. greater than 0,
     if ($apply_credit_amount < (double) '0.00') {
         $response['error'] = '1';
         $response['msg'] = $helper->generateMessage(JText::_('COM_TIENDA_PLEASE_SPECIFY_VALID_CREDIT_AMOUNT'));
         echo json_encode($response);
         return;
     }
     // less than/== their available amount & order amount?
     $userinfo = JTable::getInstance('UserInfo', 'TiendaTable');
     $userinfo->load(array('user_id' => $user_id));
     $userinfo->credits_total = (double) $userinfo->credits_total;
     if ($apply_credit_amount > $userinfo->credits_total) {
         $apply_credit_amount = $userinfo->credits_total;
     }
     // get the order object so we can populate it
     $order = $this->_order;
     // a TableOrders object (see constructor)
     // bind what you can from the post
     $order->bind($values);
     // unset the order credit because it may have been set by the bind
     $order->order_credit = '0';
     // set the currency
     Tienda::load('TiendaHelperCurrency', 'helpers.currency');
     $order->currency_id = TiendaHelperCurrency::getCurrentCurrency();
     // USD is default if no currency selected
     // set the shipping method
     $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'];
     // set the addresses
     $this->setAddresses($values, false, true);
     // get the items and add them to the order
     Tienda::load('TiendaHelperCarts', 'helpers.carts');
     $items = TiendaHelperCarts::getProductsInfo();
     foreach ($items as $item) {
         $order->addItem($item);
     }
     // get all coupons and add them to the order
     if (!empty($values['coupons'])) {
         foreach ($values['coupons'] as $coupon_id) {
             $coupon = JTable::getInstance('Coupons', 'TiendaTable');
             $coupon->load(array('coupon_id' => $coupon_id));
             $order->addCoupon($coupon);
         }
     }
     $this->addAutomaticCoupons();
     // get the order totals
     $order->calculateTotals();
     if ($apply_credit_amount > $order->order_total) {
         $apply_credit_amount = $order->order_total;
     }
     // if valid, return the html for the credit
     $response['msg'] = "<input type='hidden' name='order_credit' value='{$apply_credit_amount}'>";
     echo json_encode($response);
     return;
 }
Exemple #2
0
<?php

defined('_JEXEC') or die('Restricted access');
JHTML::_('stylesheet', 'menu.css', 'media/com_tienda/css/');
JHTML::_('script', 'tienda.js', 'media/com_tienda/js/');
JHTML::_('script', 'joomla.javascript.js', 'includes/js/');
Tienda::load('TiendaGrid', 'library.grid');
Tienda::load('TiendaHelperOrder', 'helpers.order');
Tienda::load('TiendaHelperCurrency', 'helpers.currency');
$state = @$this->state;
$order = @$this->order;
$items = @$this->orderitems;
$coupons = @$this->coupons;
$display_credits = $this->defines->get('display_credits', '0');
$currency_helper = new TiendaHelperCurrency();
$default_currency = $this->defines->get('default_currencyid', '1');
?>

<form id="opc-review-form" name="opc-review-form" action="" method="post">

    <div id="opc-order-summary">
    
    	<table class="table table-bordered table-hover">
    	<thead>
    		<tr>
    			<th class="product-name"><?php 
echo JText::_('COM_TIENDA_PRODUCT');
?>
</th>
    			<th class="product-quantity"><?php 
echo JText::_('COM_TIENDA_QUANTITY');
Exemple #3
0
 /**
  * Check if a default currencies has been selected,
  * and if the selected currency really exists
  * @return boolean
  */
 function checkDefaultCurrency()
 {
     $default_currencyid = Tienda::getInstance()->get('default_currencyid', '-1');
     if ($default_currencyid == '-1') {
         JError::raiseNotice('checkDefaultCurrency', JText::_('COM_TIENDA_NO_DEFAULT_CURRENCY_SELECTED'));
         // do not return false here to enable users to actually change the default currency
         return true;
     } else {
         Tienda::load('TiendaHelperCurrency', 'helpers.currency');
         $currency_helper = new TiendaHelperCurrency();
         $currency = $currency_helper->load($default_currencyid);
         // Check if the currency exists
         if (empty($currency->currency_id)) {
             JError::raiseNotice('checkDefaultCurrency', JText::_('COM_TIENDA_CURRENCY_DOES_NOT_EXISTS'));
             // do not return false here to enable users to actually change the default currency
             return true;
         }
     }
     return true;
 }
Exemple #4
0
 /**
  *
  * @param array $values
  * @param boolean $saveAddressesToDB Save the addresses to the database
  * @param boolean $ajax
  * @return unknown_type
  */
 public function setAddresses(&$values, $saveAddressesToDB = false, $ajax = false)
 {
     $clearAddressCache = false;
     $order = $this->_order;
     Tienda::load('TiendaHelperCurrency', 'helpers.currency');
     $currency_id = TiendaHelperCurrency::getCurrentCurrency();
     $billing_address_id = !empty($values['billing_address_id']) ? $values['billing_address_id'] : 0;
     $shipping_address_id = !empty($values['shipping_address_id']) ? $values['shipping_address_id'] : 0;
     $same_as_billing = !empty($values['sameasbilling']) ? true : false;
     $user_id = $values['user_id'];
     $billing_input_prefix = $this->billing_input_prefix;
     $shipping_input_prefix = $this->shipping_input_prefix;
     if (empty($user_id) && $this->defines->get('guest_checkout_enabled', '1')) {
         $user_id = -1;
     }
     $billing_zone_id = 0;
     $billingAddressArray = $this->getAddressArray($billing_address_id, $billing_input_prefix, $values);
     if (array_key_exists('zone_id', $billingAddressArray)) {
         $billing_zone_id = $billingAddressArray['zone_id'];
     }
     //SHIPPING ADDRESS: get shipping address from dropdown or form (depending on selection)
     $shipping_zone_id = 0;
     if ($same_as_billing) {
         $shippingAddressArray = $billingAddressArray;
     } else {
         $shippingAddressArray = $this->getAddressArray($shipping_address_id, $shipping_input_prefix, $values);
     }
     if (array_key_exists('zone_id', $shippingAddressArray)) {
         $shipping_zone_id = $shippingAddressArray['zone_id'];
     }
     // keep the array for binding during the saveOrderInfo process
     $this->_orderinfoBillingAddressArray = $this->filterArrayUsingPrefix($billingAddressArray, '', 'billing_', true);
     $this->_orderinfoShippingAddressArray = $this->filterArrayUsingPrefix($shippingAddressArray, '', 'shipping_', true);
     $this->_billingAddressArray = $billingAddressArray;
     $this->_shippingAddressArray = $shippingAddressArray;
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $billingAddress = JTable::getInstance('Addresses', 'TiendaTable');
     $shippingAddress = JTable::getInstance('Addresses', 'TiendaTable');
     // set the order billing address
     $billingAddress->bind($billingAddressArray);
     $billingAddress->user_id = $user_id;
     $billingAddress->addresstype_id = 1;
     if ($saveAddressesToDB && !$billing_address_id) {
         $clearAddressCache = true;
         $billingAddress->save();
         if (!$billing_address_id) {
             $values['billing_address_id'] = $billingAddress->address_id;
         }
     }
     $order->setAddress($billingAddress);
     // set the order shipping address
     $shippingAddress->bind($shippingAddressArray);
     $shippingAddress->user_id = $user_id;
     $shippingAddress->addresstype_id = 2;
     if ($saveAddressesToDB && !$same_as_billing && !$shipping_address_id) {
         $clearAddressCache = true;
         $shippingAddress->save();
         if (!$shipping_address_id) {
             $values['shipping_address_id'] = $shippingAddress->address_id;
         }
     }
     if ($clearAddressCache) {
         DSCModel::addIncludePath(JPATH_SITE . '/components/com_tienda/models');
         $model = DSCModel::getInstance('Addresses', 'TiendaModel');
         $model->clearCache();
     }
     $order->setAddress($shippingAddress, 'shipping');
     return $this;
 }
Exemple #5
0
 public function submitOrder()
 {
     $this->setFormat();
     $session = JFactory::getSession();
     $response = $this->getResponseObject();
     $values = JRequest::get('post');
     // Prep the post
     if (!empty($this->user->id)) {
         $values["user_id"] = $this->user->id;
         $values["email_address"] = $this->user->email;
         $values["checkout_method"] = null;
     } else {
         $userHelper = new TiendaHelperUser();
         $values["user_id"] = $userHelper->getNextGuestUserId();
     }
     $values['ip_address'] = $_SERVER['REMOTE_ADDR'];
     $values["sameasbilling"] = !empty($values["shipping_input_same_as_billing"]) ? $values["shipping_input_same_as_billing"] : false;
     if ($shippingMethod = unserialize($session->get('tienda.opc.shippingMethod'))) {
         $values['shipping_plugin'] = $shippingMethod['element'];
         $values['shipping_price'] = $shippingMethod['price'];
         $values['shipping_extra'] = $shippingMethod['extra'];
         $values['shipping_name'] = $shippingMethod['name'];
         $values['shipping_tax'] = $shippingMethod['tax'];
         $values['shipping_code'] = $shippingMethod['code'];
     }
     $values['coupons'] = array();
     if ($userCoupons = unserialize($session->get('tienda.opc.userCoupons'))) {
         foreach ($userCoupons as $coupon) {
             $values['coupons'][] = $coupon->coupon_id;
         }
     }
     if ($userCredit = unserialize($session->get('tienda.opc.userCredit'))) {
         $values['order_credit'] = $userCredit;
     }
     if (empty($values['currency_id'])) {
         Tienda::load('TiendaHelperCurrency', 'helpers.currency');
         $values['currency_id'] = TiendaHelperCurrency::getCurrentCurrency();
     }
     $model = $this->getModel('orders');
     $errorMessage = '';
     if (!($validate = $model->validate($values))) {
         $errorMessage = '<ul class="text-error">';
         foreach ($model->getErrors() as $error) {
             $errorMessage .= "<li>" . $error . "</li>";
         }
         $errorMessage .= '</ul>';
         $response->goto_section = 'review';
         $response->summary->html = $errorMessage;
         echo json_encode($response);
         return;
     }
     $options = array();
     $options["save_addresses"] = true;
     if (!($order = $model->save($values, $options))) {
         $errorMessage = '<ul class="text-error">';
         foreach ($model->getErrors() as $error) {
             $errorMessage .= "<li>" . $error . "</li>";
         }
         $errorMessage .= '</ul>';
         $response->goto_section = 'review';
         $response->summary->html = $errorMessage;
         echo json_encode($response);
         return;
     }
     $this->_order = $order;
     if (!($html = $this->getPreparePaymentForm($values, $options, $order))) {
         $errorMessage = '<ul class="text-error">';
         $errorMessage .= "<li>" . $this->getError() . "</li>";
         $errorMessage .= '</ul>';
         // get and return the error for display to the user
         $response->goto_section = 'review';
         $response->summary->html = $errorMessage;
         echo json_encode($response);
         return;
     }
     if ($html == 'free') {
         $itemid = $this->router->findItemid(array('view' => 'opc'));
         if (empty($itemid)) {
             $itemid = $this->router->findItemid(array('view' => 'checkout'));
             if (empty($itemid)) {
                 $itemid = JRequest::getInt('Itemid');
             }
         }
         $response->redirect = JRoute::_('index.php?option=com_tienda&view=opc&task=confirmPayment&Itemid=' . $itemid);
         echo json_encode($response);
         return;
     }
     $response->summary->id = 'opc-payment-prepayment';
     $response->summary->html = $html;
     $response->goto_section = 'prepare-payment';
     echo json_encode($response);
     return;
 }