/**
  * When the user logs in, their session cart should override their db-stored cart.
  * Current actions take precedence
  *
  * @param $user
  * @param $options
  * @return unknown_type
  */
 private function doLoginUser($user, $options = array())
 {
     $session = JFactory::getSession();
     $old_sessionid = $session->get('old_sessionid');
     $user['id'] = intval(JUserHelper::getUserId($user['username']));
     // Should check that Citruscart is installed first before executing
     if (!$this->_isInstalled()) {
         return;
     }
     Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
     $helper = new CitruscartHelperCarts();
     if (!empty($old_sessionid)) {
         $helper->mergeSessionCartWithUserCart($old_sessionid, $user['id']);
         JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
         $wishlist_model = JModelLegacy::getInstance('WishlistItems', 'CitruscartModel');
         $wishlist_model->setUserForSessionItems($old_sessionid, $user['id']);
     } else {
         $helper->updateUserCartItemsSessionId($user['id'], $session->getId());
     }
     $this->checkUserGroup();
     return true;
 }
Exemple #2
0
 function getCart()
 {
     Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_citruscart/models');
     // determine whether we're working with a session or db cart
     $suffix = CitruscartHelperCarts::getSuffix();
     $model = JModelLegacy::getInstance('Carts', 'CitruscartModel');
     $session = JFactory::getSession();
     $user = JFactory::getUser();
     $model->setState('filter_user', $user->id);
     if (empty($user->id)) {
         $model->setState('filter_session', $session->getId());
     }
     $list = $model->getList(false, false);
     Citruscart::load('Citruscart', 'defines');
     $config = Citruscart::getInstance();
     $show_tax = $config->get('display_prices_with_tax');
     $this->using_default_geozone = false;
     if ($show_tax) {
         Citruscart::load('CitruscartHelperUser', 'helpers.user');
         $geozones = CitruscartHelperUser::getGeoZones(JFactory::getUser()->id);
         if (empty($geozones)) {
             // use the default
             $this->using_default_geozone = true;
             $table = JTable::getInstance('Geozones', 'CitruscartTable');
             $table->load(array('geozone_id' => Citruscart::getInstance()->get('default_tax_geozone')));
             $geozones = array($table);
         }
         Citruscart::load("CitruscartHelperProduct", 'helpers.product');
         foreach ($list as &$item) {
             $taxtotal = CitruscartHelperProduct::getTaxTotal($item->product_id, $geozones);
             $item->product_price = $item->product_price + $taxtotal->tax_total;
             $item->taxtotal = $taxtotal;
         }
     }
     return $list;
 }
Exemple #3
0
 /**
  * Checks the integrity of a cart
  * to make sure all dependencies are met
  *
  * @param $cart_id
  * @param $id_type
  * @return unknown_type
  */
 function checkIntegrity($cart_id, $id_type = 'user_id')
 {
     $user_id = 0;
     $session_id = '';
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
     // get the cart's items as well as user info (if logged in)
     $model = JModelLegacy::getInstance('Carts', 'CitruscartModel');
     switch ($id_type) {
         case "session":
         case "session_id":
             $model->setState('filter_session', $cart_id);
             $session_id = $cart_id;
             break;
         case "user":
         case "user_id":
         default:
             $model->setState('filter_user', $cart_id);
             $user_id = $cart_id;
             break;
     }
     $carthelper = new CitruscartHelperCarts();
     // get the cart items
     $cart_items = $model->getList(false, false);
     if (!empty($cart_items)) {
         // foreach
         foreach ($cart_items as $citem) {
             if (!$carthelper->canAddItem($citem, $cart_id, $id_type)) {
                 JFactory::getApplication()->enqueueMessage(JText::_('COM_CITRUSCART_REMOVING_ITEM_FROM_CART_FOR_FAILED_DEPENDENCIES') . " - " . $citem->product_name, 'message');
                 $carthelper->removeCartItem($session_id, $user_id, $citem->product_id);
             }
         }
     }
     return true;
 }
Exemple #4
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;
 }
Exemple #5
0
 /**
  * Verifies the fields in a submitted form.
  * Then adds the item to the users cart
  *
  * @return unknown_type
  */
 function addChildrenToCart()
 {
     $input = JFactory::getApplication()->input;
     JSession::checkToken() or jexit('Invalid Token');
     $product_id = $input->getInt('product_id');
     $quantities = $input->get('quantities', array(0), 'request', 'array');
     $filter_category = $input->getInt('filter_category');
     Citruscart::load("CitruscartHelperRoute", 'helpers.route');
     $router = new CitruscartHelperRoute();
     if (!($itemid = $router->product($product_id, $filter_category, true))) {
         $itemid = $router->category(1, true);
     }
     // set the default redirect URL
     $redirect = "index.php?option=com_citruscart&view=products&task=view&id={$product_id}&filter_category={$filter_category}&Itemid=" . $itemid;
     $redirect = JRoute::_($redirect, false);
     Citruscart::load('CitruscartHelperBase', 'helpers._base');
     $helper = CitruscartHelperBase::getInstance();
     if (!Citruscart::getInstance()->get('shop_enabled', '1')) {
         $this->messagetype = 'notice';
         $this->message = JText::_('COM_CITRUSCART_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 = $input->getArray($_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";
     }
     Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
     $carthelper = new CitruscartHelperCarts();
     $cart_recurs = $carthelper->hasRecurringItem($cart_id, $id_type);
     // TODO get the children
     // loop thru each child,
     // get the list
     JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
     $model = JModelLegacy::getInstance('ProductRelations', 'CitruscartModel');
     $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';
             }
             if (!$product_qty) {
                 // product quantity is zero -> skip this product
                 continue;
             }
             // using a helper file to determine the product's information related to inventory
             $availableQuantity = Citruscart::getClass('CitruscartHelperProduct', '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_CITRUSCART_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', 'CitruscartTable');
             $product->load(array('product_id' => $child->product_id_to));
             // if product notforsale, fail
             if ($product->product_notforsale) {
                 $this->messagetype = 'notice';
                 $this->message = JText::_('COM_CITRUSCART_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_CITRUSCART_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_CITRUSCART_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 = JFactory::getApplication()->triggerEvent("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)) {
         // add the items to the cart
         Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
         CitruscartHelperCarts::updateCart($items);
         // fire plugin event
         $dispatcher = JDispatcher::getInstance();
         JFactory::getApplication()->triggerEvent('onAfterAddToCart', array($items, $values));
         $this->messagetype = 'message';
         $this->message = JText::_('COM_CITRUSCART_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 (Citruscart::getInstance()->get('addtocartaction', 'redirect')) {
         case "redirect":
             $returnUrl = base64_encode($redirect);
             $itemid = $router->findItemid(array('view' => 'checkout'));
             $redirect = JRoute::_("index.php?option=com_citruscart&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;
 }
Exemple #6
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'])) {
         Citruscart::load('CitruscartHelperCurrency', 'helpers.currency');
         $order->currency_id = CitruscartHelperCurrency::getCurrentCurrency();
     }
     // Store the text verion of the currency for order integrity
     Citruscart::load('CitruscartHelperOrder', 'helpers.order');
     $order->order_currency = CitruscartHelperOrder::currencyToParameters($order->currency_id);
     $saveAddressesToDB = empty($options["save_addresses"]) ? false : true;
     $this->setAddresses($values, $saveAddressesToDB);
     // set the shipping method
     if (isset($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
         Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
         $reviewitems = CitruscartHelperCarts::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;
 }
 /**
  * 
  * Enter description here ...
  * @param unknown_type $values
  * @param unknown_type $files
  * @return return_type
  */
 function addToCart($values = array(), $files = array())
 {
     // create cart object out of item properties
     $item = new JObject();
     $item->user_id = $this->user_id;
     $item->product_id = (int) $this->product_id;
     $item->product_qty = !empty($this->product_quantity) ? $this->product_quantity : '1';
     $item->product_attributes = $this->product_attributes;
     $item->vendor_id = $this->vendor_id;
     $item->cartitem_params = $this->wishlistitem_params;
     // onAfterCreateItemForAddToCart: plugin can add values to the item before it is being validated /added
     // once the extra field(s) have been set, they will get automatically saved
     $dispatcher = JDispatcher::getInstance();
     $results = JFactory::getApplication()->triggerEvent("onAfterCreateItemForAddToCart", array($item, $values, $files));
     foreach ($results as $result) {
         foreach ($result as $key => $value) {
             $item->set($key, $value);
         }
     }
     if (!$this->isAvailable()) {
         return false;
     }
     Citruscart::load('CitruscartHelperProduct', 'helpers.product');
     $product_helper = new CitruscartHelperProduct();
     $availableQuantity = $product_helper->getAvailableQuantity($this->product_id, $this->product_attributes);
     if ($availableQuantity->product_check_inventory && $item->product_qty > $availableQuantity->quantity) {
         $this->setError(JText::_(JText::sprintf("COM_CITRUSCART_NOT_AVAILABLE_QUANTITY", $availableQuantity->product_name, $item->product_qty)));
         return false;
     }
     Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
     $carthelper = new CitruscartHelperCarts();
     // does the user/cart match all dependencies?
     $canAddToCart = $carthelper->canAddItem($item, $this->user_id, 'user_id');
     if (!$canAddToCart) {
         $this->setError(JText::_('COM_CITRUSCART_CANNOT_ADD_ITEM_TO_CART') . " - " . $carthelper->getError());
         return false;
     }
     // no matter what, fire this validation plugin event for plugins that extend the checkout workflow
     $results = array();
     $dispatcher = JDispatcher::getInstance();
     $results = JFactory::getApplication()->triggerEvent("onBeforeAddToCart", array(&$item, $values));
     for ($i = 0; $i < count($results); $i++) {
         $result = $results[$i];
         if (!empty($result->error)) {
             $this->setError(JText::_('COM_CITRUSCART_CANNOT_ADD_ITEM_TO_CART') . " - " . $result->message);
             return false;
         }
     }
     // if here, add to cart
     // After login, session_id is changed by Joomla, so store this for reference
     $session = JFactory::getSession();
     $session->set('old_sessionid', $session->getId());
     // add the item to the cart
     $cartitem = $carthelper->addItem($item);
     // fire plugin event
     $dispatcher = JDispatcher::getInstance();
     JFactory::getApplication()->triggerEvent('onAfterAddToCart', array($cartitem, $values));
     return $cartitem;
 }
Exemple #8
0
 /**
  * Validate Coupon Code
  *
  * @return unknown_type
  */
 function validateCouponCode()
 {
     $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);
     $coupon_code = $input->get('coupon_code', '');
     $response = array();
     $response['msg'] = '';
     $response['error'] = '';
     // check if coupon code is valid
     $user_id = JFactory::getUser()->id;
     Citruscart::load('CitruscartHelperCoupon', 'helpers.coupon');
     $helper_coupon = new CitruscartHelperCoupon();
     $coupon = $helper_coupon->isValid($coupon_code, 'code', $user_id);
     if (!$coupon) {
         $response['error'] = '1';
         $response['msg'] = $helper->generateMessage($helper_coupon->getError());
         echo json_encode($response);
         return;
     }
     if (!empty($values['coupons']) && in_array($coupon->coupon_id, $values['coupons'])) {
         $response['error'] = '1';
         $response['msg'] = $helper->generateMessage(JText::_('COM_CITRUSCART_THIS_COUPON_ALREADY_ADDED_TO_THE_ORDER'));
         echo json_encode($response);
         return;
     }
     // TODO Check that the user can add this coupon to the order
     $can_add = true;
     if (!$can_add) {
         $response['error'] = '1';
         $response['msg'] = $helper->generateMessage(JText::_('COM_CITRUSCART_CANNOT_ADD_THIS_COUPON_TO_ORDER'));
         echo json_encode($response);
         return;
     }
     // Check per product coupon code
     $ids = array();
     $items = CitruscartHelperCarts::getProductsInfo();
     foreach ($items as $item) {
         $ids[] = $item->product_id;
     }
     if ($coupon->coupon_type == '1') {
         $check = $helper_coupon->checkByProductIds($coupon->coupon_id, $ids);
         if (!$check) {
             $response['error'] = '1';
             $response['msg'] = $helper->generateMessage(JText::_('COM_CITRUSCART_THIS_COUPON_NOT_RELATED_TO_PRODUCT_IN_YOUR_CART'));
             echo json_encode($response);
             return;
         }
     }
     // if valid, return the html for the coupon
     $response['msg'] = " <input type='hidden' name='coupons[]' value='{$coupon->coupon_id}'>";
     echo json_encode($response);
     return;
 }
 /**
  * Processes the sale payment
  *
  * @param  array   $data IPN data
  * @return boolean Did the IPN Validate?
  * @access protected
  */
 public function _processSale($data, $ipnValidationFailed = '')
 {
     /*
      * 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');
     }
     if (empty($data['custom'])) {
         $errors[] = JText::_('PAYPAL MESSAGE INVALID ORDERPAYMENTID');
         return count($errors) ? implode("\n", $errors) : '';
     }
     // load the orderpayment record and set some values
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     $orderpayment = JTable::getInstance('OrderPayments', 'CitruscartTable');
     $orderpayment->load($data['custom']);
     if (empty($data['custom']) || empty($orderpayment->orderpayment_id)) {
         $errors[] = JText::_('PAYPAL MESSAGE INVALID ORDERPAYMENTID');
         return count($errors) ? implode("\n", $errors) : '';
     }
     $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
     Citruscart::load('CitruscartHelperBase', 'helpers._base');
     $stored_amount = CitruscartHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => ''));
     $respond_amount = CitruscartHelperBase::number($data['mc_gross'], array('thousands' => ''));
     if ($stored_amount != $respond_amount) {
         $errors[] = JText::_('PAYPAL MESSAGE 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
     Citruscart::load('CitruscartHelperOrder', 'helpers.order');
     Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
     $order = JTable::getInstance('Orders', 'CitruscartTable');
     $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 = Citruscart::getInstance('pending_order_state', '1');
         // PENDING
         // Update quantities for echeck payments
         CitruscartHelperOrder::updateProductQuantities($orderpayment->order_id, '-');
         // remove items from cart
         CitruscartHelperCarts::removeOrderItems($orderpayment->order_id);
         // send email
         $send_email = true;
     } 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
         Citruscart::load("CitruscartHelperBase", 'helpers._base');
         $helper = CitruscartHelperBase::getInstance('Email');
         $model = Citruscart::getClass("CitruscartModelOrders", "models.orders");
         $model->setId($orderpayment->order_id);
         $order = $model->getItem();
         $helper->sendEmailNotices($order, 'new_order');
     }
     return count($errors) ? implode("\n", $errors) : '';
 }
Exemple #10
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_citruscart/tables');
     $order = JTable::getInstance('Orders', 'CitruscartTable');
     $order->load($order_id);
     if (empty($order->order_id)) {
         // TODO we must make sure this class is always instantiated
         $this->setError(JText::_('COM_CITRUSCART_INVALID_ORDER_ID'));
         return false;
     }
     // Fire an doCompletedOrderTasks event
     JFactory::getApplication()->triggerEvent('doCompletedOrderTasks', array($order_id));
     // 0. Enable One-Time Purchase Subscriptions
     CitruscartHelperOrder::enableNonRecurringSubscriptions($order_id);
     // 1. Update quantities
     CitruscartHelperOrder::updateProductQuantities($order_id, '-');
     // 2. remove items from cart
     Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
     CitruscartHelperCarts::removeOrderItems($order_id);
     // 3. add productfiles to product downloads
     CitruscartHelperOrder::enableProductDownloads($order_id);
     // 4. do SQL queries
     $helper = CitruscartHelperBase::getInstance('Sql');
     $helper->processOrder($order_id);
     // register commission if amigos is installed
     $helper = CitruscartHelperBase::getInstance('Amigos');
     $helper->createCommission($order_id);
     // change ticket limits if billets is installed
     $helper = CitruscartHelperBase::getInstance('Billets');
     $helper->processOrder($order_id);
     // add to JUGA Groups if JUGA installed
     $helper = CitruscartHelperBase::getInstance('Juga');
     $helper->processOrder($order_id);
     // change core ACL if set
     $helper = CitruscartHelperBase::getInstance('User');
     $helper->processOrder($order_id);
     // do Ambra Subscriptions Integration processes
     $helper = CitruscartHelperBase::getInstance('Ambrasubs');
     $helper->processOrder($order_id);
     // increase the hit counts for coupons in the order
     $helper = CitruscartHelperBase::getInstance('Coupon');
     $helper->processOrder($order_id);
     if ($error) {
         $this->setError(implode('<br/>', $errors));
         return false;
     } else {
         $order->completed_tasks = '1';
         $order->store();
         return true;
     }
 }
Exemple #11
0
 /**
  * Given an order_id, will remove the order's items from the user's cart
  *
  * @param unknown_type $order_id
  * @return unknown_type
  */
 function removeOrderItemsFromCart($order_id)
 {
     Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
     CitruscartHelperCarts::removeOrderItems($order_id);
 }
Exemple #12
0
 function getProductsInfo()
 {
     Citruscart::load("CitruscartHelperProduct", 'helpers.product');
     $product_helper = CitruscartHelperBase::getInstance('Product');
     DSCModel::addIncludePath(JPATH_SITE . DS . 'components/com_citruscart/models');
     DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     $model = DSCModel::getInstance('Carts', 'CitruscartModel');
     $session = JFactory::getSession();
     $user_id = $session->get('user_id', '', 'citruscart_pos');
     $model->setState('filter_user', $user_id);
     Citruscart::load("CitruscartHelperBase", 'helpers._base');
     Citruscart::load("CitruscartHelperCarts", 'helpers.carts');
     $user_helper = CitruscartHelperBase::getInstance('User');
     $filter_group = $user_helper->getUserGroup($user_id);
     $model->setState('filter_group', $filter_group);
     $cartitems = $model->getList();
     $productitems = array();
     foreach ($cartitems as $cartitem) {
         //echo Citruscart::dump($cartitem);
         unset($productModel);
         $productModel = DSCModel::getInstance('Products', 'CitruscartModel');
         $filter_group = $user_helper->getUserGroup($user_id, $cartitem->product_id);
         $productModel->setState('filter_group', $filter_group);
         $productModel->setId($cartitem->product_id);
         if ($productItem = $productModel->getItem(false)) {
             $productItem->price = $productItem->product_price = !$cartitem->product_price_override->override ? $cartitem->product_price : $productItem->price;
             //we are not overriding the price if its a recurring && price
             if (!$productItem->product_recurs && $cartitem->product_price_override->override) {
                 // at this point, ->product_price holds the default price for the product,
                 // but the user may qualify for a discount based on volume or date, so let's get that price override
                 // TODO Shouldn't we remove this?  Is it necessary?  $cartitem has already done this in the carts model!
                 $productItem->product_price_override = $product_helper->getPrice($productItem->product_id, $cartitem->product_qty, $filter_group, JFactory::getDate()->toSql());
                 if (!empty($productItem->product_price_override)) {
                     $productItem->product_price = $productItem->product_price_override->product_price;
                 }
             }
             if ($productItem->product_check_inventory) {
                 // using a helper file,To determine the product's information related to inventory
                 $availableQuantity = $product_helper->getAvailableQuantity($productItem->product_id, $cartitem->product_attributes);
                 if ($availableQuantity->product_check_inventory && $cartitem->product_qty > $availableQuantity->quantity && $availableQuantity->quantity >= 1) {
                     JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_CITRUSCART_CART_QUANTITY_ADJUSTED', $productItem->product_name, $cartitem->product_qty, $availableQuantity->quantity));
                     $cartitem->product_qty = $availableQuantity->quantity;
                 }
                 // removing the product from the cart if it's not available
                 if ($availableQuantity->quantity == 0) {
                     if (empty($cartitem->user_id)) {
                         CitruscartHelperCarts::removeCartItem($session_id, $cartitem->user_id, $cartitem->product_id);
                     } else {
                         CitruscartHelperCarts::removeCartItem($cartitem->session_id, $cartitem->user_id, $cartitem->product_id);
                     }
                     JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_CITRUSCART_NOT_AVAILABLE') . " " . $productItem->product_name);
                     continue;
                 }
             }
             // TODO Push this into the orders object->addItem() method?
             $orderItem = JTable::getInstance('OrderItems', 'CitruscartTable');
             $orderItem->product_id = $productItem->product_id;
             $orderItem->orderitem_sku = $cartitem->product_sku;
             $orderItem->orderitem_name = $productItem->product_name;
             $orderItem->orderitem_quantity = $cartitem->product_qty;
             $orderItem->orderitem_price = $productItem->product_price;
             $orderItem->orderitem_attributes = $cartitem->product_attributes;
             $orderItem->orderitem_attribute_names = $cartitem->attributes_names;
             $orderItem->orderitem_attributes_price = $cartitem->orderitem_attributes_price;
             $orderItem->orderitem_final_price = ($orderItem->orderitem_price + $orderItem->orderitem_attributes_price) * $orderItem->orderitem_quantity;
             $results = JFactory::getApplication()->triggerEvent("onGetAdditionalOrderitemKeyValues", array($cartitem));
             foreach ($results as $result) {
                 foreach ($result as $key => $value) {
                     $orderItem->set($key, $value);
                 }
             }
             // TODO When do attributes for selected item get set during admin-side order creation?
             array_push($productitems, $orderItem);
         }
     }
     return $productitems;
 }
}
require_once dirname(__FILE__) . '/helper.php';
// include lang files
$lang = JFactory::getLanguage();
$lang->load('com_citruscart', JPATH_BASE);
$lang->load('com_citruscart', JPATH_ADMINISTRATOR);
$mainframe = JFactory::getApplication();
$document = JFactory::getDocument();
// params
$display_null = $params->get('display_null', '1');
$null_text = $params->get('null_text', 'No Items in Your Cart');
$isAjax = $mainframe->getUserState('mod_usercart.isAjax');
$ajax = $isAjax == '1';
// Grab the cart
Citruscart::load('CitruscartHelperCarts', 'helpers.carts');
$items = CitruscartHelperCarts::getProductsInfo();
$num = count($items);
// Convert the cart to a "fake" order, to show totals and others things
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
$orderTable = JTable::getInstance('Orders', 'CitruscartTable');
foreach ($items as $item) {
    $orderTable->addItem($item);
}
$items = $orderTable->getItems();
Citruscart::load('Citruscart', 'defines');
$config = Citruscart::getInstance();
$show_tax = $config->get('display_prices_with_tax');
if ($show_tax) {
    Citruscart::load('CitruscartHelperUser', 'helpers.user');
    $geozones = CitruscartHelperUser::getGeoZones(JFactory::getUser()->id);
    if (empty($geozones)) {
 /**
  *
  * @return unknown_type
  */
 function update()
 {
     $input = JFactory::getApplication()->input;
     $model = $this->getModel(strtolower(CitruscartHelperCarts::getSuffix()));
     $this->_setModelState();
     $user = JFactory::getUser();
     $session = JFactory::getSession();
     $cids = $input->get('cid', array(0), '', 'ARRAY');
     $product_attributes = $input->get('product_attributes', array(0), '', 'ARRAY');
     $quantities = $input->get('quantities', array(0), '', 'ARRAY');
     $post = $input->getArray($_POST);
     $msg = JText::_('COM_CITRUSCART_QUANTITIES_UPDATED');
     $remove = $input->getString('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 = CitruscartHelperCarts::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
                 JFactory::getApplication()->triggerEvent('onRemoveFromCart', array($item));
             }
         }
     } else {
         foreach ($quantities as $cart_id => $value) {
             $carts = JTable::getInstance('Carts', 'CitruscartTable');
             $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 = CitruscartHelperCarts::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 = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getAvailableQuantity($product_id, $product_attributes[$cart_id]);
             if ($availableQuantity->product_check_inventory && $value > $availableQuantity->quantity) {
                 JFactory::getApplication()->enqueueMessage(JText::sprintf("COM_CITRUSCART_NOT_AVAILABLE_QUANTITY", $availableQuantity->product_name, $value));
                 continue;
             }
             if ($value > 1) {
                 $product = JTable::getInstance('Products', 'CitruscartTable');
                 $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_CITRUSCART_REACHED_MAXIMUM_QUANTITY_FOR_THIS_OBJECT') . $max;
                             $value = $max;
                         }
                     }
                     if ($min) {
                         if ($value < $min) {
                             $msg = JText::_('COM_CITRUSCART_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
                     JFactory::getApplication()->triggerEvent('onRemoveFromCart', array($item));
                 }
             } else {
                 $row->load($cart_id);
                 $row->product_qty = $vals['product_qty'];
                 $row->save();
             }
         }
     }
     $carthelper = new CitruscartHelperCarts();
     $carthelper->fixQuantities();
     if (empty($user->id)) {
         $carthelper->checkIntegrity($session->getId(), 'session_id');
     } else {
         $carthelper->checkIntegrity($user->id);
     }
     Citruscart::load("CitruscartHelperRoute", 'helpers.route');
     $router = new CitruscartHelperRoute();
     $redirect = JRoute::_("index.php?option=com_citruscart&view=carts&Itemid=" . $router->findItemid(array('view' => 'carts')), false);
     $this->setRedirect($redirect, $msg);
 }