예제 #1
0
파일: pos.php 프로젝트: annggeel/tienda
 function getOrderSummary(&$order)
 {
     $model = $this->getModel('carts');
     JLoader::register("TiendaViewPOS", JPATH_ADMINISTRATOR . "/components/com_tienda/views/pos/view.html.php");
     $view = new TiendaViewPOS();
     $view->set('_controller', 'pos');
     $view->set('_view', 'pos');
     $view->set('_doTask', true);
     $view->set('hidemenu', false);
     $view->setModel($model, true);
     $view->assign('state', $model->getState());
     $config = Tienda::getInstance();
     $show_tax = $config->get('display_prices_with_tax');
     $view->assign('show_tax', $show_tax);
     $view->assign('using_default_geozone', false);
     $view->assign('order', $order);
     $orderitems = $order->getItems();
     Tienda::load("TiendaHelperTax", 'helpers.tax');
     if ($show_tax) {
         $geozones = $order->getBillingGeoZones();
         if (empty($geozones)) {
             // use the default
             $view->assign('using_default_geozone', true);
             $geozones = array($config->get('default_tax_geozone'));
         } else {
             foreach ($geozones as $key => $value) {
                 $geozones[$key] = $value->geozone_id;
             }
         }
         $taxes = TiendaHelperTax::calculateGeozonesTax($orderitems, 4, $geozones);
     }
     $product_helper = TiendaHelperBase::getInstance('Product');
     $order_helper = TiendaHelperBase::getInstance('Order');
     $showShipping = false;
     $tax_sum = 0;
     $notfoundShipping = true;
     foreach ($orderitems as &$item) {
         //check shipping if required
         if ($notfoundShipping && ($isShippingEnabled = $product_helper->isShippingEnabled($item->product_id))) {
             $showShipping = true;
             $notfoundShipping = false;
         }
         if ($show_tax) {
             $item->price = $item->orderitem_price + floatval($item->orderitem_attributes_price) + $taxes->product_taxes[$item->product_id];
             $item->orderitem_final_price = $item->price * $item->orderitem_quantity;
             $order->order_subtotal += $taxes->product_taxes[$item->product_id] * $item->orderitem_quantity;
         } else {
             $item->price = $item->orderitem_price + floatval($item->orderitem_attributes_price);
         }
     }
     $view->assign('orderitems', $orderitems);
     if ($showShipping) {
         $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
     $view->setLayout('ordersummary');
     ob_start();
     $view->display();
     $html = ob_get_contents();
     ob_end_clean();
     return $html;
 }
예제 #2
0
파일: tax.php 프로젝트: annggeel/tienda
 /**
  * Calculate taxes on list of products
  *
  * @param $products						Array of products
  * @param $source						Source of tax calculation (final_price '1', product_price '2', orderitem_price '3')
  * @param $billing_address		Actual customer's billing address
  * @param $shipping_address		Actual customer's shipping address
  * @param $tax_type						for the future use
  *
  * @return Associative array with indexes product_id of products with arrays with list of their tax rates (names and rates)
  */
 public static function calculateTax($products, $source = 1, $billing_address = null, $shipping_address = null, $tax_type = null)
 {
     $result = new stdClass();
     $result->tax_total = 0.0;
     $result->tax_rate_rates = array();
     $result->tax_class_rates = array();
     $result->product_taxes = array();
     if (!is_array($products)) {
         return $result;
     }
     Tienda::load('TiendaHelperShipping', 'helpers.shipping');
     Tienda::load('TiendaQuery', 'library.query');
     Tienda::load('TiendaTools', 'library.tools');
     if ($billing_address) {
         $billing_zones = TiendaHelperShipping::getGeoZones($billing_address->zone_id, '1', $billing_address->postal_code);
     } else {
         $billing_zones = array();
     }
     if (!empty($billing_zones)) {
         foreach ($billing_zones as $key => $value) {
             $billing_zones[$key] = $value->geozone_id;
         }
     }
     //load the default geozones when user is logged out and the config is to show tax
     if (empty($billing_zones)) {
         $geozones = TiendaHelperUser::getGeoZones(JFactory::getUser()->id);
         if (empty($geozones)) {
             // use the default
             $billing_zones = array(Tienda::getInstance()->get('default_tax_geozone'));
         } else {
             foreach ($geozones as $key => $value) {
                 $billing_zones[$key] = $value->geozone_id;
             }
         }
     }
     return TiendaHelperTax::calculateGeozonesTax($products, $source, $billing_zones);
 }
예제 #3
0
파일: product.php 프로젝트: annggeel/tienda
 /**
  * Get the cart button form for a specific product
  *
  * @param int $product_id 	The id of the product
  * @return html	The add to cart form
  */
 public static function getCartButton($product_id, $layout = 'product_buy', $values = array(), &$callback_js = '')
 {
     if (is_array($values) && !count($values)) {
         $values = JRequest::get('request');
     }
     $html = '';
     $page = JRequest::getVar('page', 'product');
     $isPOS = $page == 'pos';
     if ($isPOS) {
         JLoader::register("TiendaViewPOS", JPATH_ADMINISTRATOR . "/components/com_tienda/views/pos/view.html.php");
         $view = new TiendaViewPOS();
     } else {
         JLoader::register("TiendaViewProducts", JPATH_SITE . "/components/com_tienda/views/products/view.html.php");
         $view = new TiendaViewProducts();
     }
     $model = JModel::getInstance('Products', 'TiendaModel');
     $model->setId($product_id);
     $model->setState('task', 'product_buy');
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $helper_product = TiendaHelperBase::getInstance('Product');
     Tienda::load('TiendaHelperUser', 'helpers.user');
     $user_id = JFactory::getUser()->id;
     if ($isPOS) {
         $user_id = JRequest::getInt('user_id', $user_id);
     }
     $filter_group = TiendaHelperUser::getUserGroup($user_id, $product_id);
     $qty = isset($values['product_qty']) && !empty($values['product_qty']) ? $values['product_qty'] : 1;
     $model->setState('filter_group', $filter_group);
     $model->setState('product.qty', $qty);
     $model->setState('user.id', $user_id);
     $row = $model->getItem(false, true, false);
     if ($row->product_notforsale || Tienda::getInstance()->get('shop_enabled') == '0') {
         return $html;
     }
     // This enable this helper method to be used outside of tienda
     if ($isPOS) {
         $view->set('_controller', 'pos');
         $view->set('_view', 'pos');
     } else {
         $view->addTemplatePath(JPATH_SITE . '/components/com_tienda/views/products/tmpl');
         $view->addTemplatePath(JPATH_SITE . '/templates/' . JFactory::getApplication('site')->getTemplate() . '/html/com_tienda/products/');
         // add extra templates
         $view->addTemplatePath(Tienda::getPath('product_buy_templates'));
         $view->set('_controller', 'products');
         $view->set('_view', 'products');
     }
     $view->set('_doTask', true);
     $view->set('hidemenu', true);
     $view->setModel($model, true);
     $view->setLayout($layout);
     $view->product_id = $product_id;
     $view->values = $values;
     $filter_category = $model->getState('filter_category', JRequest::getInt('filter_category', (int) @$values['filter_category']));
     $view->filter_category = $filter_category;
     if ($isPOS) {
         $view->validation = "index.php?option=com_tienda&view=pos&task=validate&format=raw";
     } else {
         $view->validation = "index.php?option=com_tienda&view=products&task=validate&format=raw";
     }
     $config = Tienda::getInstance();
     // TODO What about this??
     $show_shipping = $config->get('display_prices_with_shipping');
     if ($show_shipping) {
         $article_link = $config->get('article_shipping', '');
         $shipping_cost_link = JRoute::_('index.php?option=com_content&view=article&id=' . $article_link);
         $view->shipping_cost_link = $shipping_cost_link;
     }
     $quantity_min = 1;
     if ($row->quantity_restriction) {
         $quantity_min = $row->quantity_min;
     }
     $invalidQuantity = '0';
     $attributes = array();
     $attr_orig = array();
     if (empty($values)) {
         $product_qty = $quantity_min;
         // get the default set of attribute_csv
         if (!isset($row->default_attributes)) {
             $default_attributes = $helper_product->getDefaultAttributes($product_id);
         } else {
             $default_attributes = $row->default_attributes;
         }
         sort($default_attributes);
         $attributes_csv = implode(',', $default_attributes);
         $availableQuantity = $helper_product->getAvailableQuantity($product_id, $attributes_csv);
         if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) {
             $invalidQuantity = '1';
         }
         $attr_orig = $attributes = $default_attributes;
     } else {
         $product_qty = !empty($values['product_qty']) ? (int) $values['product_qty'] : $quantity_min;
         // TODO only display attributes available based on the first selected attribute?
         foreach ($values as $key => $value) {
             if (substr($key, 0, 10) == 'attribute_') {
                 if (empty($value)) {
                     $attributes[$key] = 0;
                 } else {
                     $attributes[$key] = $value;
                 }
             }
         }
         if (!count($attributes)) {
             // no attributes are selected -> use default
             if (!isset($row->default_attributes)) {
                 $attributes = $helper_product->getDefaultAttributes($product_id);
             } else {
                 $attributes = $row->default_attributes;
             }
         }
         $attr_orig = $attributes;
         sort($attributes);
         // Add 0 to attributes to include all the root attributes
         //$attributes[] = 0;//remove this one. its causing the getAvailableQuantity to not get quantity because of wrong csv
         // For getting child opts
         $view->selected_opts = json_encode(array_merge($attributes, array('0')));
         $attributes_csv = implode(',', $attributes);
         // Integrity checks on quantity being added
         if ($product_qty < 0) {
             $product_qty = '1';
         }
         // using a helper file to determine the product's information related to inventory
         $availableQuantity = $helper_product->getAvailableQuantity($product_id, $attributes_csv);
         if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) {
             $invalidQuantity = '1';
         }
     }
     // adjust the displayed price based on the selected or default attributes
     TiendaHelperProduct::calculateProductAttributeProperty($row, $attr_orig, 'price', 'product_weight');
     $show_tax = $config->get('display_prices_with_tax');
     $show_product = $config->get('display_category_cartbuttons');
     $view->show_tax = $show_tax;
     $row->tax = '0';
     $row->taxtotal = '0';
     if ($show_tax) {
         // finish TiendaHelperUser::getGeoZone -- that's why this isn't working
         Tienda::load('TiendaHelperUser', 'helpers.user');
         $geozones_user = TiendaHelperUser::getGeoZones($user_id);
         if (empty($geozones_user)) {
             $geozones = array(Tienda::getInstance()->get('default_tax_geozone'));
         } else {
             $geozones = array();
             foreach ($geozones_user as $value) {
                 $geozones[] = $value->geozone_id;
             }
         }
         Tienda::load('TiendaHelperTax', 'helpers.tax');
         $product = new stdClass();
         $product->product_price = $row->price;
         $product->product_id = $product_id;
         $tax = TiendaHelperTax::calculateGeozonesTax(array($product), 2, $geozones);
         $row->taxtotal = $tax->tax_total;
         $row->tax = $tax->tax_total;
     }
     $row->_product_quantity = $product_qty;
     if ($page == 'product' || $isPOS) {
         $display_cartbutton = Tienda::getInstance()->get('display_product_cartbuttons', '1');
     } else {
         $display_cartbutton = Tienda::getInstance()->get('display_category_cartbuttons', '1');
     }
     $view->page = $page;
     $view->display_cartbutton = $display_cartbutton;
     $view->availableQuantity = $availableQuantity;
     $view->invalidQuantity = $invalidQuantity;
     if ($isPOS) {
         $view->product = $row;
     } else {
         $view->item = $row;
     }
     $dispatcher = JDispatcher::getInstance();
     ob_start();
     $dispatcher->trigger('onDisplayProductAttributeOptions', array($row->product_id));
     $view->onDisplayProductAttributeOptions = ob_get_contents();
     ob_end_clean();
     $html = $view->loadTemplate();
     if (isset($view->callback_js) && !empty($view->callback_js)) {
         $callback_js = $view->callback_js;
     }
     return $html;
 }