Example #1
0
 /**
  *
  * Method to check config, user group and product state (if recurs).
  * Then get right values accordingly
  * @param array $items - cart items
  * @param boolean - config to show tax or not
  * @return object
  */
 function checkItems(&$items, $show_tax = false)
 {
     if (empty($items)) {
         return array();
     }
     Tienda::load('TiendaHelperUser', 'helpers.user');
     Tienda::load("TiendaHelperProduct", 'helpers.product');
     Tienda::load('TiendaHelperTax', 'helpers.tax');
     if ($show_tax) {
         $taxes = TiendaHelperTax::calculateTax($items, 1);
     }
     $subtotal = 0;
     foreach ($items as $item) {
         if ($show_tax) {
             $item->product_price = $item->product_price + $taxes->product_taxes[$item->product_id];
             $item->taxtotal = $taxes->product_taxes[$item->product_id];
         }
         $item->subtotal = $item->product_price * $item->product_qty;
         $subtotal = $subtotal + $item->subtotal;
     }
     $cartObj = new stdClass();
     $cartObj->items = $items;
     $cartObj->subtotal = $subtotal;
     return $cartObj;
 }
Example #2
0
 /**
  * Calculates the tax totals for the order
  * using the array of items in the order object
  * 
  * @return unknown_type
  */
 function calculateTaxTotals()
 {
     $config = Tienda::getInstance();
     $show_tax = $config->get('display_prices_with_tax');
     $calc_tax_shipping = $config->get('calc_tax_shipping');
     Tienda::load("TiendaHelperTax", 'helpers.tax');
     $this->_taxrate_amounts = array();
     $this->_taxclass_amounts = array();
     $items = $this->getItems();
     $shipping_address = $this->getShippingAddress();
     $billing_address = $this->getBillingAddress();
     if ($calc_tax_shipping) {
         $taxes = TiendaHelperTax::calculateTax($items, 1, $shipping_address, $shipping_address);
     } else {
         $taxes = TiendaHelperTax::calculateTax($items, 1, $billing_address, $shipping_address);
     }
     foreach ($items as $item) {
         $item->orderitem_tax = $taxes->product_taxes[$item->product_id];
         if ($show_tax) {
             $item->orderitem_final_price += $item->orderitem_tax;
         }
     }
     foreach (@$taxes->tax_rate_rates as $key => $value) {
         $applied_tax = $value->applied_tax;
         // add this as one of the taxrates applicable to this order
         if (empty($this->_taxrates[$key])) {
             $this->_taxrates[$key] = $value;
         }
         // track the total amount of tax applied to this order for this taxrate
         if (empty($this->_taxrate_amounts[$key])) {
             $this->_taxrate_amounts[$key] = 0;
         }
         $this->_taxrate_amounts[$key] += $applied_tax;
     }
     foreach (@$taxes->tax_class_rates as $key => $value) {
         $applied_tax = $value->applied_tax;
         // add this as one of the taxclasses applicable to this order
         if (empty($this->_taxclasses[$key])) {
             $this->_taxclasses[$key] = $value;
         }
         // track the total amount of tax applied to this order for this taxclass
         if (empty($this->_taxclass_amounts[$key])) {
             $this->_taxclass_amounts[$key] = 0;
         }
         $this->_taxclass_amounts[$key] += $applied_tax;
     }
     $this->order_tax = $taxes->tax_total;
     // Allow tax calculation to be modified via plugins
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger("onCalculateTaxTotals", array($this));
 }
Example #3
0
 /**
  * Prepares data for and returns the html of the order summary layout.
  * This assumes that $this->_order has already had its properties set
  *
  * @return unknown_type
  */
 public function getOrderSummary($layout = 'cart')
 {
     // get the order object
     $order = $this->_order;
     // a TableOrders object (see constructor)
     Tienda::load('TiendaHelperCoupon', 'helpers.coupon');
     // Coupons
     $coupons_id = array();
     $coupons = $order->getCoupons();
     foreach ($coupons as $cg) {
         foreach ($cg as $c) {
             if ($c->coupon_type == '1') {
                 $coupons_id = array_merge($coupons_id, TiendaHelperCoupon::getCouponProductIds(@$c->coupon_id));
             }
         }
     }
     $model = $this->getModel('carts');
     $user = $this->user;
     $model->setState('filter_user', $user->id);
     $view = $this->getView($this->get('suffix'), 'html');
     $view->set('_controller', $this->get('suffix'));
     $view->set('_view', $this->get('suffix'));
     $view->set('_doTask', true);
     $view->set('hidemenu', true);
     $view->setModel($model, true);
     $view->assign('state', $model->getState());
     $view->assign('coupons', $coupons_id);
     $config = $this->defines;
     $show_tax = $config->get('display_prices_with_tax');
     $view->assign('show_tax', $show_tax);
     $view->assign('using_default_geozone', false);
     $view->assign('order', $order);
     Tienda::load("TiendaHelperBase", 'helpers._base');
     $product_helper = TiendaHelperBase::getInstance('Product');
     $order_helper = TiendaHelperBase::getInstance('Order');
     $tax_sum = 0;
     $orderitems = $order->getItems();
     $taxes = TiendaHelperTax::calculateTax($orderitems, 4, $order->getBillingAddress(), $order->getShippingAddress());
     foreach ($orderitems as $item) {
         $item->price = $item->orderitem_final_price / $item->orderitem_quantity;
         if ($show_tax) {
             $order->order_subtotal += $item->orderitem_tax;
         }
     }
     $view->assign('orderitems', $orderitems);
     // Checking whether shipping is required
     $showShipping = false;
     $cartsModel = $this->getModel('carts');
     if ($isShippingEnabled = $cartsModel->getShippingIsEnabled()) {
         $showShipping = true;
         $view->assign('shipping_total', $order->getShippingTotal());
     }
     $view->assign('showShipping', $showShipping);
     //START onDisplayOrderItem: trigger plugins for extra orderitem information
     if (!empty($orderitems)) {
         $onDisplayOrderItem = $order_helper->onDisplayOrderItems($orderitems);
         $view->assign('onDisplayOrderItem', $onDisplayOrderItem);
     }
     //END onDisplayOrderItem
     $coupons_present = false;
     $model = JModel::getInstance('Coupons', 'TiendaModel');
     $model->setState('filter_enabled', '1');
     if ($coupons = $model->getList()) {
         $coupons_present = true;
     }
     $view->assign('coupons_present', $coupons_present);
     $view->setLayout($layout);
     $view->setTask(true);
     ob_start();
     $view->display();
     $html = ob_get_contents();
     ob_end_clean();
     return $html;
 }
Example #4
0
 public function deleteCartItem()
 {
     $response = new stdClass();
     $response->html = '';
     $response->error = false;
     $user = JFactory::getUser();
     $model = $this->getModel('carts');
     $table = $model->getTable();
     $id = JRequest::getInt('cartitem_id');
     $keys = array('user_id' => $user->id, 'cart_id' => $id);
     $table->load($keys);
     if (!empty($table->cart_id)) {
         if ($table->delete()) {
             $response->html = JText::_('COM_TIENDA_CARTITEM_DELETED');
         } else {
             $response->html = JText::_('COM_TIENDA_DELETE_FAILED');
             $response->error = true;
         }
     } else {
         $response->html = JText::_('COM_TIENDA_INVALID_REQUEST');
         $response->error = true;
     }
     // we deleted the item so we have to recalculate the subtotal
     $response->subtotal = 0;
     if ($response->error == false) {
         $show_tax = $this->defines->get('display_prices_with_tax');
         $model = $this->getModel($this->get('suffix'));
         $this->_setModelState();
         $items = $model->getList();
         Tienda::load('TiendaHelperUser', 'helpers.user');
         Tienda::load('TiendaHelperTax', 'helpers.tax');
         if ($show_tax) {
             $taxes = TiendaHelperTax::calculateTax($items, 2);
         }
         foreach ($items as $item) {
             if ($show_tax) {
                 $item->product_price += $taxes->product_taxes[$item->product_id];
             }
             $response->subtotal += $item->product_price * $item->product_qty;
         }
         $response->subtotal = TiendaHelperBase::currency($response->subtotal);
     }
     echo json_encode($response);
     return;
 }
Example #5
0
 /**
  * Gets a product's related items
  * formatted for display
  *
  * @param int $address_id
  * @return string html
  */
 function getRelationshipsHtml($view, $product_id, $relation_type = 'relates')
 {
     $html = '';
     $validation = "";
     // get the list
     JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
     $model = JModel::getInstance('ProductRelations', 'TiendaModel');
     $model->setState('filter_relation', $relation_type);
     $user = JFactory::getUser();
     $model->setState('filter_group', $relation_type);
     switch ($relation_type) {
         case "requires":
             $model->setState('filter_product_from', $product_id);
             $check_quantity = false;
             $layout = 'product_requirements';
             break;
         case "parent":
         case "child":
         case "children":
             $model->setState('filter_product_from', $product_id);
             $check_quantity = true;
             $validation = "index.php?option=com_tienda&view=products&task=validateChildren&format=raw";
             $layout = 'product_children';
             break;
         case "relates":
             $model->setState('filter_product', $product_id);
             $check_quantity = false;
             $layout = 'product_relations';
             break;
         default:
             return $html;
             break;
     }
     $query = $model->getQuery();
     $query->order('p_from.ordering ASC, p_to.ordering ASC');
     if ($items = $model->getList()) {
         $filter_category = $model->getState('filter_category', JRequest::getVar('filter_category'));
         if (empty($filter_category)) {
             $categories = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getCategories($product_id);
             if (!empty($categories)) {
                 $filter_category = $categories[0];
             }
         }
         $userId = JFactory::getUser()->id;
         $config = Tienda::getInstance();
         $show_tax = $config->get('display_prices_with_tax');
         Tienda::load('TiendaHelperTax', 'helpers.tax');
         if ($show_tax) {
             $taxes = TiendaHelperTax::calculateTax($items, 2);
         }
         foreach ($items as $key => $item) {
             if ($check_quantity) {
                 // TODO Unset $items[$key] if
                 // this is out of stock &&
                 // check_inventory &&
                 // item for sale
             }
             if ($item->product_id_from == $product_id) {
                 // display the _product_to
                 $item->product_id = $item->product_id_to;
                 $item->product_name = $item->product_name_to;
                 $item->product_model = $item->product_model_to;
                 $item->product_sku = $item->product_sku_to;
                 $item->product_price = $item->product_price_to;
             } else {
                 // display the _product_from
                 $item->product_id = $item->product_id_from;
                 $item->product_name = $item->product_name_from;
                 $item->product_model = $item->product_model_from;
                 $item->product_sku = $item->product_sku_from;
                 $item->product_price = $item->product_price_from;
             }
             $itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->product($item->product_id, $filter_category, true);
             $item->itemid = JRequest::getInt('Itemid', $itemid);
             $item->tax = 0;
             if ($show_tax) {
                 $tax = $taxes->product_taxes[$item->product_id];
                 $item->taxtotal = $tax;
                 $item->tax = $tax;
             }
         }
     } else {
         return '';
     }
     $view->setModel($model, true);
     $lyt = $view->getLayout();
     $view->setLayout($layout);
     $product_relations = new stdClass();
     $product_relations->items = $items;
     $product_relations->product_id = $product_id;
     $product_relations->show = $product_id;
     $product_relations->filter_category = $filter_category;
     $product_relations->validation = $validation;
     $product_relations->show_tax = $show_tax;
     $view->product_relations_data = $product_relations;
     ob_start();
     $view->display();
     $html = ob_get_contents();
     ob_end_clean();
     unset($view->product_relations_data);
     $view->setLayout($lyt);
     return $html;
 }