Example #1
0
# Websites: http://citruscart.com
# Technical Support:  Forum - http://citruscart.com/forum/index.html
-------------------------------------------------------------------------*/
defined('_JEXEC') or die('Restricted access');
JHtml::_('stylesheet', 'media/citruscart/css/menu.css');
JHtml::_('script', 'media/citruscart/js/citruscart.js', false, false);
JHtml::_('script', 'joomla.javascript.js', 'includes/js/');
Citruscart::load('CitruscartGrid', 'library.grid');
Citruscart::load('CitruscartHelperOrder', 'helpers.order');
Citruscart::load('CitruscartHelperCurrency', '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 CitruscartHelperCurrency();
$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_CITRUSCART_PRODUCT');
?>
</th>
    			<th class="product-quantity"><?php 
Example #2
0
 /**
  * Validates the credit amount and applies it to the order
  * return unknown_type
  */
 function validateApplyCredit()
 {
     $input = JFactory::getApplication()->input;
     JLoader::import('com_citruscart.library.json', JPATH_ADMINISTRATOR . '/components');
     $elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', $input->getString('elements')));
     // convert elements to array that can be binded
     Citruscart::load('CitruscartHelperBase', 'helpers._base');
     $helper = CitruscartHelperBase::getInstance();
     $values = $helper->elementsToArray($elements);
     $user_id = $this->user->id;
     $apply_credit_amount = (double) $input->get('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_CITRUSCART_PLEASE_SPECIFY_VALID_CREDIT_AMOUNT'));
         echo json_encode($response);
         return;
     }
     // less than/== their available amount & order amount?
     $userinfo = JTable::getInstance('UserInfo', 'CitruscartTable');
     $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
     Citruscart::load('CitruscartHelperCurrency', 'helpers.currency');
     $order->currency_id = CitruscartHelperCurrency::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
     Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
     $items = CitruscartHelperCarts::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', 'CitruscartTable');
             $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;
 }
Example #3
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;
     Citruscart::load('CitruscartHelperCurrency', 'helpers.currency');
     $currency_id = CitruscartHelperCurrency::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_citruscart/tables');
     $billingAddress = JTable::getInstance('Addresses', 'CitruscartTable');
     $shippingAddress = JTable::getInstance('Addresses', 'CitruscartTable');
     // 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_citruscart/models');
         $model = DSCModel::getInstance('Addresses', 'CitruscartModel');
         $model->clearCache();
     }
     $order->setAddress($shippingAddress, 'shipping');
     return $this;
 }
Example #4
0
 /**
  * Check if a default currencies has been selected,
  * and if the selected currency really exists
  * @return boolean
  */
 function checkDefaultCurrency()
 {
     $default_currencyid = Citruscart::getInstance()->get('default_currencyid', '-1');
     if ($default_currencyid == '-1') {
         JError::raiseNotice('checkDefaultCurrency', JText::_('COM_CITRUSCART_NO_DEFAULT_CURRENCY_SELECTED'));
         // do not return false here to enable users to actually change the default currency
         return true;
     } else {
         Citruscart::load('CitruscartHelperCurrency', 'helpers.currency');
         $currency_helper = new CitruscartHelperCurrency();
         $currency = $currency_helper->load($default_currencyid);
         // Check if the currency exists
         if (empty($currency->currency_id)) {
             JError::raiseNotice('checkDefaultCurrency', JText::_('COM_CITRUSCART_CURRENCY_DOES_NOT_EXISTS'));
             // do not return false here to enable users to actually change the default currency
             return true;
         }
     }
     return true;
 }
Example #5
0
 public function submitOrder()
 {
     $app = JFactory::getApplication();
     $input = JFactory::getApplication()->input;
     $this->setFormat();
     $session = JFactory::getSession();
     $response = $this->getResponseObject();
     // Prep the post
     $values = $input->getArray($_POST);
     if (!empty($this->user->id)) {
         $values["user_id"] = $this->user->id;
         $values["email_address"] = $this->user->email;
         $values["checkout_method"] = null;
         if (isset($values['billing_address_id']) && $values['billing_address_id']) {
             //$billing_add = unserialize($session->get('citruscart.opc.billingAddress'));
             $billing_add = unserialize($session->get('citruscart.opc.billingAddress'));
             if (is_object($billing_add)) {
                 $prefix = "billing_input";
                 $billing = JArrayHelper::fromObject($billing_add);
                 $new_key = array();
                 $key = array_keys($billing);
                 for ($a = 0; $a < count($key); $a++) {
                     $new_key[$a] = $prefix . '_' . $key[$a];
                 }
                 $billingAdd = array_combine($new_key, array_values($billing));
                 $values = array_merge($values, $billingAdd);
                 $values['country_id'] = $billing['country_id'];
                 $values['zone_id'] = $billing['zone_id'];
             }
         }
         if (isset($values['shipping_address_id']) && $values['shipping_address_id']) {
             $shipping_add = unserialize($session->get('citruscart.opc.shippingAddress'));
             if (is_object($shipping_add)) {
                 $prefix = "shipping_input";
                 $shipping = JArrayHelper::fromObject($shipping_add);
                 $new_key = array();
                 $key = array_keys($shipping);
                 for ($a = 0; $a < count($key); $a++) {
                     $new_key[$a] = $prefix . '_' . $key[$a];
                 }
                 $shippingAdd = array_combine($new_key, array_values($shipping));
                 $values = array_merge($values, $shippingAdd);
             }
         }
     } else {
         $userHelper = new CitruscartHelperUser();
         $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"] : "";
     if ($shippingMethod = unserialize($session->get('citruscart.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('citruscart.opc.userCoupons'))) {
         foreach ($userCoupons as $coupon) {
             $values['coupons'][] = $coupon->coupon_id;
         }
     }
     if ($userCredit = unserialize($session->get('citruscart.opc.userCredit'))) {
         $values['order_credit'] = $userCredit;
     }
     if (empty($values['currency_id'])) {
         Citruscart::load('CitruscartHelperCurrency', 'helpers.currency');
         $values['currency_id'] = CitruscartHelperCurrency::getCurrentCurrency();
     }
     $model = $this->getModel('orders');
     //print_r($values);
     $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);
         $app->close();
     }
     $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);
         $app->close();
     }
     $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);
         $app->close();
     }
     if ($html == 'free') {
         $itemid = $this->router->findItemid(array('view' => 'opc'));
         if (empty($itemid)) {
             $itemid = $this->router->findItemid(array('view' => 'checkout'));
             if (empty($itemid)) {
                 $itemid = $input->getInt('Itemid');
             }
         }
         $response->redirect = JRoute::_('index.php?option=com_citruscart&view=opc&task=confirmPayment&Itemid=' . $itemid);
         echo json_encode($response);
         $app->close();
     }
     $response->summary->id = 'opc-payment-prepayment';
     $response->summary->html = $html;
     $response->goto_section = 'prepare-payment';
     echo json_encode($response);
     $app->close();
 }