コード例 #1
0
ファイル: checkout.php プロジェクト: joomlacorner/citruscart
 /**
  * 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)
     Citruscart::load('CitruscartHelperCoupon', '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, CitruscartHelperCoupon::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);
     Citruscart::load("CitruscartHelperBase", 'helpers._base');
     $product_helper = CitruscartHelperBase::getInstance('Product');
     $order_helper = CitruscartHelperBase::getInstance('Order');
     $tax_sum = 0;
     $orderitems = $order->getItems();
     $taxes = CitruscartHelperTax::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 = JModelLegacy::getInstance('Coupons', 'CitruscartModel');
     $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;
 }
コード例 #2
0
ファイル: products.php プロジェクト: joomlacorner/citruscart
 /**
  * Gets a product's related items
  * formatted for display
  *
  * @param int $address_id
  * @return string html
  */
 function getRelationshipsHtml($view, $product_id, $relation_type = 'relates')
 {
     $input = JFactory::getApplication()->input;
     $html = '';
     $validation = "";
     // get the list
     JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
     $model = JModelLegacy::getInstance('ProductRelations', 'CitruscartModel');
     $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_citruscart&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', $input->getString('filter_category'));
         if (empty($filter_category)) {
             $categories = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getCategories($product_id);
             if (!empty($categories)) {
                 $filter_category = $categories[0];
             }
         }
         $userId = JFactory::getUser()->id;
         $config = Citruscart::getInstance();
         $show_tax = $config->get('display_prices_with_tax');
         Citruscart::load('CitruscartHelperTax', 'helpers.tax');
         if ($show_tax) {
             $taxes = CitruscartHelperTax::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 = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->product($item->product_id, $filter_category, true);
             $item->itemid = $input->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;
 }
コード例 #3
0
ファイル: orders.php プロジェクト: joomlacorner/citruscart
 /**
  * Calculates the tax totals for the order
  * using the array of items in the order object
  *
  * @return unknown_type
  */
 function calculateTaxTotals()
 {
     $config = Citruscart::getInstance();
     $show_tax = $config->get('display_prices_with_tax');
     $calc_tax_shipping = $config->get('calc_tax_shipping');
     Citruscart::load("CitruscartHelperTax", '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 = CitruscartHelperTax::calculateTax($items, 1, $shipping_address, $shipping_address);
     } else {
         $taxes = CitruscartHelperTax::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
     JFactory::getApplication()->triggerEvent("onCalculateTaxTotals", array($this));
 }
コード例 #4
0
ファイル: carts.php プロジェクト: joomlacorner/citruscart
 public function deleteCartItem()
 {
     $input = JFactory::getApplication()->input;
     $response = new stdClass();
     $response->html = '';
     $response->error = false;
     $user = JFactory::getUser();
     $model = $this->getModel('carts');
     $table = $model->getTable();
     $id = $input->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_CITRUSCART_CARTITEM_DELETED');
         } else {
             $response->html = JText::_('COM_CITRUSCART_DELETE_FAILED');
             $response->error = true;
         }
     } else {
         $response->html = JText::_('COM_CITRUSCART_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();
         Citruscart::load('CitruscartHelperUser', 'helpers.user');
         Citruscart::load('CitruscartHelperTax', 'helpers.tax');
         if ($show_tax) {
             $taxes = CitruscartHelperTax::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 = CitruscartHelperBase::currency($response->subtotal);
     }
     echo json_encode($response);
     return;
 }
コード例 #5
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();
     }
     Citruscart::load('CitruscartHelperUser', 'helpers.user');
     Citruscart::load("CitruscartHelperProduct", 'helpers.product');
     Citruscart::load('CitruscartHelperTax', 'helpers.tax');
     if ($show_tax) {
         $taxes = CitruscartHelperTax::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;
 }