/** * Redefine setError method inherited from Joomla! JObject class * * @access public * @since 0.6 */ function setError($error) { jincimport('utility.servicelocator'); $servicelocator = ServiceLocator::getInstance(); $logger = $servicelocator->getLogger(); $logger->finer(get_class($this) . ': ' . JText::_($error)); parent::setError($error); }
/** * Validates the data submitted based on the suffix provided * * @param $suffix * @return html */ function _processSuffix($suffix = '') { $html = ""; switch ($suffix) { case "2": if (!($verify = $this->_verifyDB())) { JError::raiseNotice('_verifyDB', $this->getError()); $html .= $this->_renderForm('1'); } else { // migrate the data and output the results $html .= $this->_doMigration($verify); } break; case "1": if (!($verify = $this->_verifyDB())) { JError::raiseNotice('_verifyDB', $this->getError()); $html .= $this->_renderForm('1'); } else { $suffix++; $vars = new JObject(); $vars->preview = $verify; $vars->state = $this->_getState(); $vars->state->uploaded_file = $this->_uploaded_file; $vars->setError($this->getError()); // display a 'connection verified' message // and request confirmation before migrating data $html .= $this->_renderForm($suffix, $vars); $html .= $this->_renderView($suffix, $vars); } break; default: $html .= $this->_renderForm('1'); break; } return $html; }
/** * Returns a shipping estimate, unformatted. * * @param int $shipping_method_id * @param int $geozone_id * @param array $orderItems an array of CitruscartTableOrderItems objects, each with ->product_id and ->orderitem_quantity * * @return object with ->shipping_rate_price and ->shipping_rate_handling and ->shipping_tax_total, all decimal(12,5) */ public function getTotal($shipping_method_id, $geozone_id, $orderItems) { $return = new JObject(); $return->shipping_rate_price = '0.00000'; $return->shipping_rate_handling = '0.00000'; $return->shipping_tax_rate = '0.00000'; $return->shipping_tax_total = '0.00000'; // cast product_id as an array $orderItems = (array) $orderItems; // determine the shipping method type JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $shippingmethod = JTable::getInstance('ShippingMethods', 'CitruscartTable'); $shippingmethod->load($shipping_method_id); if (empty($shippingmethod->shipping_method_id)) { // TODO if this is an object, setError, otherwise return false, or 0.000? $return->setError(JText::_('COM_CITRUSCART_UNDEFINED_SHIPPING_METHOD')); return $return; } switch ($shippingmethod->shipping_method_type) { case "2": // 2 = per order // if any of the products in the order require shipping $order_ships = false; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); foreach ($orderItems as $item) { //$pid = $orderItems[$i]->product_id; $pid = $item->product_id; $product = JTable::getInstance('Products', 'CitruscartTable'); $product->load($pid); if (!empty($product->product_ships)) { $product_id = $item->product_id; $order_ships = true; } } if ($order_ships) { //$shippingrate = CitruscartHelperShipping::getRate( $shipping_method_id, $geozone_id, $product_id ); //$return->shipping_rate_price = $shippingrate->shipping_rate_price; //$return->shipping_rate_handling = $shippingrate->shipping_rate_handling; } break; case "1": case "0": // 0 = per item // 1 = weight based $rates = array(); foreach ($orderItems as $item) { $pid = $item->product_id; $qty = $item->orderitem_quantity; //$rates[$pid] = CitruscartHelperShipping::getRate( $shipping_method_id, $geozone_id, $pid, $shippingmethod->shipping_method_type ); //$return->shipping_rate_price += ($rates[$pid]->shipping_rate_price * $qty); //$return->shipping_rate_handling += ($rates[$pid]->shipping_rate_handling * $qty); } break; default: // TODO if this is an object, setError, otherwise return false, or 0.000? $return->setError(JText::_('COM_CITRUSCART_INVALID_SHIPPING_METHOD_TYPE')); return $return; break; } // get the shipping tax rate and total $return->shipping_tax_rate = CitruscartHelperShipping::getTaxRate($shipping_method_id, $geozone_id); $return->shipping_tax_total = $return->shipping_tax_rate / 100 * ($return->shipping_rate_price + $return->shipping_rate_handling); return $return; }
/** * * Returns an object with the total cost of shipping for this method and the array of geozones * * @param unknown_type $shipping_method_id * @param array $geozones * @param unknown_type $orderItems * @param unknown_type $order_id */ protected function getTotal($shipping_method_id, $geozones, $orderItems, $geozones_taxes) { $return = new JObject(); $return->shipping_rate_id = '0'; $return->shipping_rate_price = '0.00000'; $return->shipping_rate_handling = '0.00000'; $return->shipping_tax_rates = '0.00000'; $return->shipping_tax_total = '0.00000'; $rate_exists = false; $geozone_rates = array(); //include custom modals $this->includeCustomModel('ShippingMethods'); $this->includeCustomModel('ShippingRates'); // cast product_id as an array $orderItems = (array) $orderItems; // determine the shipping method type $this->includeCustomTables('shipping_standard'); $this->includeCustomTables(); $shippingmethod = JTable::getInstance('ShippingMethods', 'Table'); $shippingmethod->load($shipping_method_id); if (empty($shippingmethod->shipping_method_id)) { // TODO if this is an object, setError, otherwise return false, or 0.000? $return->setError(JText::_('J2STORE_UNDEFINED_SHIPPING_METHOD')); return $return; } //initiliase cart helper $carthelper = new J2StoreHelperCart(); //initliase cart model JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_j2store/models'); $cart_model = new J2StoreModelMyCart(); switch ($shippingmethod->shipping_method_type) { case "2": // 2 = per order - price based // Get the total of the order, and find the rate for that $total = 0; //foreach ($orderItems as $item) // { // $total += $item->orderitem_final_price; // } $order_ships = false; $products = $cart_model->getDataNew(); foreach ($products as $product) { //check if shipping is enabled for this item if (!empty($product['shipping'])) { $order_ships = true; $total += $product['total']; // product total } } if ($order_ships) { foreach ($geozones as $geozone) { unset($rate); $geozone_id = $geozone->geozone_id; if (empty($geozone_rates[$geozone_id]) || !is_array($geozone_rates[$geozone_id])) { $geozone_rates[$geozone_id] = array(); } // JModelLegacy::addIncludePath( JPATH_ADMINISTRATOR.'/components/com_j2store/models' ); $model = JModelLegacy::getInstance('ShippingRates', 'J2StoreModel'); $model->setState('filter_shippingmethod', $shipping_method_id); $model->setState('filter_geozone', $geozone_id); $model->setState('filter_weight', $total); // Use weight as total $items = $model->getList(); if (count($items) < 1) { //return JTable::getInstance('ShippingRates', 'Table'); } else { $rate = $items[0]; $geozone_rates[$geozone_id]['0'] = $rate; // if $rate->shipping_rate_id is empty, then no real rate was found if (!empty($rate->shipping_rate_id)) { $rate_exists = true; } $geozone_rates[$geozone_id]['0']->qty = '1'; $geozone_rates[$geozone_id]['0']->shipping_method_type = $shippingmethod->shipping_method_type; } } } break; case "1": // 1 = per order - quantity based // first, get the total quantity of shippable items for the entire order // then, figure out the rate for this number of items (use the weight range field) + geozone // 1 = per order - quantity based // first, get the total quantity of shippable items for the entire order // then, figure out the rate for this number of items (use the weight range field) + geozone case "0": // 0 = per order - flat rate // 0 = per order - flat rate case "5": // 5 = per order - weight based // if any of the products in the order require shipping $sum_weight = 0; $count_shipped_items = 0; $order_ships = false; $products = $cart_model->getDataNew(); foreach ($products as $product) { //check if shipping is enabled for this item if (!empty($product['shipping'])) { $product_id = $product['product_id']; $order_ships = true; $sum_weight += $product['weight_total']; // we already have a weight total. So we dont have to multiply weight*quantity again $count_shipped_items += $product['quantity']; } } if ($order_ships) { foreach ($geozones as $geozone) { unset($rate); $geozone_id = $geozone->geozone_id; if (empty($geozone_rates[$geozone_id]) || !is_array($geozone_rates[$geozone_id])) { $geozone_rates[$geozone_id] = array(); } switch ($shippingmethod->shipping_method_type) { case "0": // don't use weight, just do flat rate for entire order // regardless of weight and regardless of the number of items $rate = $this->getRate($shipping_method_id, $geozone_id, $product_id); break; case "1": // get the shipping rate for the entire order using the count of all products in the order that ship $rate = $this->getRate($shipping_method_id, $geozone_id, $product_id, '1', $count_shipped_items); break; default: // get the shipping rate for the entire order using the sum weight of all products in the order that ship $rate = $this->getRate($shipping_method_id, $geozone_id, $product_id, '1', $sum_weight); break; } $geozone_rates[$geozone_id]['0'] = $rate; // if $rate->shipping_rate_id is empty, then no real rate was found if (!empty($rate->shipping_rate_id)) { $rate_exists = true; } $geozone_rates[$geozone_id]['0']->qty = '1'; $geozone_rates[$geozone_id]['0']->shipping_method_type = $shippingmethod->shipping_method_type; } } break; case "6": case "4": case "3": // 6 = per item - price based, a percentage of the product's price // 4 = per item - weight based // 3 = per item - flat rate $rates = array(); $products = $cart_model->getDataNew(); foreach ($products as $product) { // print_r($item); $pid = $product['product_id']; $qty = $product['quantity']; $hash = $product['key']; foreach ($geozones as $geozone) { unset($rate); $geozone_id = $geozone->geozone_id; if (empty($geozone_rates[$geozone_id]) || !is_array($geozone_rates[$geozone_id])) { $geozone_rates[$geozone_id] = array(); } // $geozone_rates[$geozone_id][$pid] contains the shipping rate object for ONE product_id at this geozone. // You need to multiply by the quantity later $rate = $this->getRate($shipping_method_id, $geozone_id, $pid, $shippingmethod->shipping_method_type); //price per item if ($shippingmethod->shipping_method_type == '6') { // the rate is a percentage of the product's price $rate->shipping_rate_price = $rate->shipping_rate_price / 100 * $item->orderitem_final_price; $geozone_rates[$geozone_id][$hash] = $rate; $geozone_rates[$geozone_id][$hash]->shipping_method_type = $shippingmethod->shipping_method_type; $geozone_rates[$geozone_id][$hash]->qty = '1'; // If the method_type == 6, qty should be 1 (we don't need to multiply later, in the "calc for the entire method", since this is a percentage of the orderitem_final_price) //weight per item //if weight based per item, we need to use weight. //Per product weight (including the option weight) is already present in the products array. So pass it. } elseif ($shippingmethod->shipping_method_type == '4') { $rate = $this->getRate($shipping_method_id, $geozone_id, $pid, '1', $product['weight']); $geozone_rates[$geozone_id][$hash] = $rate; $geozone_rates[$geozone_id][$hash]->shipping_method_type = $shippingmethod->shipping_method_type; $geozone_rates[$geozone_id][$hash]->qty = $qty; } else { //obviously, this is flat rate per item $geozone_rates[$geozone_id][$hash] = $rate; $geozone_rates[$geozone_id][$hash]->shipping_method_type = $shippingmethod->shipping_method_type; $geozone_rates[$geozone_id][$hash]->qty = $qty; } // if $rate->shipping_rate_id is empty, then no real rate was found if (!empty($rate->shipping_rate_id)) { $rate_exists = true; } } } break; default: $this->setError(JText::_('J2STORE_INVALID_SHIPPING_METHOD_TYPE')); return false; break; } if (!$rate_exists) { $this->setError(JText::_('J2STORE_NO_RATE_FOUND')); return false; } $shipping_tax_rates = array(); $shipping_method_price = 0; $shipping_method_handling = 0; $shipping_method_tax_total = 0; $j2tax = new J2StoreTax(); // now calc tax for the entire method foreach ($geozone_rates as $geozone_id => $geozone_rate_array) { foreach ($geozone_rate_array as $geozone_rate) { if ($shippingmethod->tax_class_id) { $value = $geozone_rate->shipping_rate_price * $geozone_rate->qty + $geozone_rate->shipping_rate_handling; $tax_rates = $j2tax->getRates($shippingmethod->tax_class_id); $shipping_tax_rates[$geozone_id] = 0; foreach ($tax_rates as $tax_rate) { $shipping_tax_rates[$geozone_id] += $tax_rate['rate']; } $shipping_method_tax_total += $j2tax->getTax($value, $shippingmethod->tax_class_id); } $shipping_method_price += $geozone_rate->shipping_rate_price * $geozone_rate->qty; $shipping_method_handling += $geozone_rate->shipping_rate_handling; } } // return formatted object $return->shipping_rate_price = $shipping_method_price; $return->shipping_rate_handling = $shipping_method_handling; $return->shipping_tax_rates = $shipping_tax_rates; $return->shipping_tax_total = $shipping_method_tax_total; $return->shipping_method_id = $shipping_method_id; $return->shipping_method_name = $shippingmethod->shipping_method_name; // print_r($return); return $return; }
/** * * Returns an object with the total cost of shipping for this method and the array of geozones * * @param unknown_type $shipping_method_id * @param array $geozones * @param unknown_type $orderItems * @param unknown_type $order_id */ protected function getTotal($shipping_method_id, $geozones, $orderItems, $geozones_taxes) { $return = new JObject(); $return->shipping_rate_id = '0'; $return->shipping_rate_price = '0.00000'; $return->shipping_rate_handling = '0.00000'; $return->shipping_tax_rate = '0.00000'; $return->shipping_tax_total = '0.00000'; $rate_exists = false; $geozone_rates = array(); // cast product_id as an array $orderItems = (array) $orderItems; // determine the shipping method type $this->includeCustomTables('shipping_standard'); $shippingmethod = JTable::getInstance('ShippingMethods', 'TiendaTable'); $shippingmethod->load($shipping_method_id); if (empty($shippingmethod->shipping_method_id)) { // TODO if this is an object, setError, otherwise return false, or 0.000? $return->setError(JText::_('COM_TIENDA_UNDEFINED_SHIPPING_METHOD')); return $return; } switch ($shippingmethod->shipping_method_type) { case "6": // 5 = per order - price based // Get the total of the order, and find the rate for that $total = 0; foreach ($orderItems as $item) { $total += $item->orderitem_final_price; } foreach ($geozones as $geozone) { unset($rate); $geozone_id = $geozone->geozone_id; if (empty($geozone_rates[$geozone_id]) || !is_array($geozone_rates[$geozone_id])) { $geozone_rates[$geozone_id] = array(); } JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = JModel::getInstance('ShippingRates', 'TiendaModel'); $model->setState('filter_shippingmethod', $shipping_method_id); $model->setState('filter_geozone', $geozone_id); $model->setState('filter_weight', $total); // Use weight as total $items = $model->getList(); if (empty($items)) { return JTable::getInstance('ShippingRates', 'TiendaTable'); } $rate = $items[0]; $geozone_rates[$geozone_id]['0'] = $rate; // if $rate->shipping_rate_id is empty, then no real rate was found if (!empty($rate->shipping_rate_id)) { $rate_exists = true; } $geozone_rates[$geozone_id]['0']->qty = '1'; $geozone_rates[$geozone_id]['0']->shipping_method_type = $shippingmethod->shipping_method_type; } break; case "5": // 5 = per order - quantity based // first, get the total quantity of shippable items for the entire order // then, figure out the rate for this number of items (use the weight range field) + geozone // 5 = per order - quantity based // first, get the total quantity of shippable items for the entire order // then, figure out the rate for this number of items (use the weight range field) + geozone case "3": case "2": // 2 = per order - weight based // 3 = per order - flat rate // if any of the products in the order require shipping $sum_weight = 0; $count_shipped_items = 0; $order_ships = false; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); foreach ($orderItems as $item) { // find out if the order ships // and while looping through, sum the weight of all shippable products in the order $pid = $item->product_id; $product = JTable::getInstance('Products', 'TiendaTable'); $product->load($pid); if (!empty($product->product_ships)) { $product_id = $item->product_id; $order_ships = true; $sum_weight += $product->product_weight * $item->orderitem_quantity; $count_shipped_items += $item->orderitem_quantity; } } if ($order_ships) { foreach ($geozones as $geozone) { unset($rate); $geozone_id = $geozone->geozone_id; if (empty($geozone_rates[$geozone_id]) || !is_array($geozone_rates[$geozone_id])) { $geozone_rates[$geozone_id] = array(); } switch ($shippingmethod->shipping_method_type) { case "3": // don't use weight, just do flat rate for entire order // regardless of weight and regardless of the number of items $rate = $this->getRate($shipping_method_id, $geozone_id, $product_id); break; case "5": // get the shipping rate for the entire order using the count of all products in the order that ship $rate = $this->getRate($shipping_method_id, $geozone_id, $product_id, '1', $count_shipped_items); break; default: // get the shipping rate for the entire order using the sum weight of all products in the order that ship $rate = $this->getRate($shipping_method_id, $geozone_id, $product_id, '1', $sum_weight); break; } $geozone_rates[$geozone_id]['0'] = $rate; // if $rate->shipping_rate_id is empty, then no real rate was found if (!empty($rate->shipping_rate_id)) { $rate_exists = true; } $geozone_rates[$geozone_id]['0']->qty = '1'; $geozone_rates[$geozone_id]['0']->shipping_method_type = $shippingmethod->shipping_method_type; } } break; case "4": case "1": case "0": // 0 = per item - flat rate // 1 = per item - weight based // 4 = per item - price based, a percentage of the product's price $rates = array(); foreach ($orderItems as $item) { $pid = $item->product_id; $qty = $item->orderitem_quantity; foreach ($geozones as $geozone) { unset($rate); $geozone_id = $geozone->geozone_id; if (empty($geozone_rates[$geozone_id]) || !is_array($geozone_rates[$geozone_id])) { $geozone_rates[$geozone_id] = array(); } // $geozone_rates[$geozone_id][$pid] contains the shipping rate object for ONE product_id at this geozone. // You need to multiply by the quantity later $rate = $this->getRate($shipping_method_id, $geozone_id, $pid, $shippingmethod->shipping_method_type); if ($shippingmethod->shipping_method_type == '4') { // the rate is a percentage of the product's price $rate->shipping_rate_price = $rate->shipping_rate_price / 100 * $item->orderitem_final_price; $geozone_rates[$geozone_id][$pid] = $rate; $geozone_rates[$geozone_id][$pid]->shipping_method_type = $shippingmethod->shipping_method_type; $geozone_rates[$geozone_id][$pid]->qty = '1'; // If the method_type == 4, qty should be 1 (we don't need to multiply later, in the "calc for the entire method", since this is a percentage of the orderitem_final_price) } else { $geozone_rates[$geozone_id][$pid] = $rate; $geozone_rates[$geozone_id][$pid]->shipping_method_type = $shippingmethod->shipping_method_type; $geozone_rates[$geozone_id][$pid]->qty = $qty; } // if $rate->shipping_rate_id is empty, then no real rate was found if (!empty($rate->shipping_rate_id)) { $rate_exists = true; } } } break; default: $this->setError(JText::_('COM_TIENDA_INVALID_SHIPPING_METHOD_TYPE')); return false; break; } if (!$rate_exists) { $this->setError(JText::_('COM_TIENDA_NO_RATE_FOUND')); return false; } $shipping_tax_rates = array(); $shipping_method_price = 0; $shipping_method_handling = 0; $shipping_method_tax_total = 0; // now calc for the entire method foreach ($geozone_rates as $geozone_id => $geozone_rate_array) { foreach ($geozone_rate_array as $geozone_rate) { $shipping_tax_rates[$geozone_id] = 0; foreach ($geozones_taxes as $gz_tax) { $shipping_tax_rates[$geozone_id] += $this->getTaxRate($shipping_method_id, $gz_tax->geozone_id); } $shipping_method_price += $geozone_rate->shipping_rate_price * $geozone_rate->qty; $shipping_method_handling += $geozone_rate->shipping_rate_handling; $shipping_method_tax_total += $shipping_tax_rates[$geozone_id] / 100 * ($geozone_rate->shipping_rate_price + $geozone_rate->shipping_rate_handling); } } // return formatted object $return->shipping_rate_price = $shipping_method_price; $return->shipping_rate_handling = $shipping_method_handling; $return->shipping_tax_rates = $shipping_tax_rates; $return->shipping_tax_total = $shipping_method_tax_total; $return->shipping_method_id = $shipping_method_id; $return->shipping_method_name = $shippingmethod->shipping_method_name; return $return; }
/** * Overrides JObject's setError() method to cater for logging * * @param string $message The error message */ function setError($message) { parent::setError($message); JoomlapackLogger::WriteLog(_JP_LOG_ERROR, $message); }
public function getTotal($shipping_method_id, $orderItems) { $doc = JFactory::getDocument(); $return = new JObject(); $return->shipping_rate_id = '0'; $return->shipping_rate_price = '0.00000'; $return->shipping_rate_handling = '0.00000'; $rate_exists = false; // cast product_id as an array $orderItems = (array) $orderItems; // determine the shipping method type JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2store' . DS . 'tables'); $shippingmethod = JTable::getInstance('ShippingMethods', 'Table'); $shippingmethod->load($shipping_method_id); if (empty($shippingmethod->id)) { // TODO if this is an object, setError, otherwise return false, or 0.000? $return->setError(JText::_("Undefined Shipping Method")); return $return; } switch ($shippingmethod->shipping_method_type) { case "2": // 5 = per order - price based // Get the total of the order, and find the rate for that $total = 0; foreach ($orderItems as $item) { $total += $item->orderitem_final_price; } JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2store' . DS . 'models'); $model = JModelLegacy::getInstance('ShippingRates', 'K2StoreModel'); $model->setState('filter_shippingmethod', $shipping_method_id); $model->setState('filter_weight', $total); // Use weight as total $items = $model->getList(); if (empty($items)) { return JTable::getInstance('ShippingRates', 'Table'); } $rate = $items[0]; // if $rate->shipping_rate_id is empty, then no real rate was found if (!empty($rate->shipping_rate_id)) { $rate_exists = true; } break; case "1": // 1 = per order - quantity based // first, get the total quantity of shippable items for the entire order // then, figure out the rate for this number of items (use the weight range field) + geozone // 1 = per order - quantity based // first, get the total quantity of shippable items for the entire order // then, figure out the rate for this number of items (use the weight range field) + geozone case "0": // 0 = per order - flat rate // if any of the products in the order require shipping $count_shipped_items = 0; $order_ships = false; foreach ($orderItems as $item) { // find out if the order ships // and while looping through, sum the weight of all shippable products in the order $pid = $item->product_id; require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2store' . DS . 'library' . DS . 'k2item.php'; $product_helper = new K2StoreItem(); $isShips = $product_helper->isShippingEnabled($pid); if (!empty($isShips)) { $product_id = $item->product_id; $order_ships = true; $count_shipped_items += $item->orderitem_quantity; } } if ($order_ships) { switch ($shippingmethod->shipping_method_type) { case "1": // quantity //based get the shipping rate for the entire order using the count of all products in the order that ship $rate = $this->getRate($shipping_method_id, $product_id, '1', $count_shipped_items); break; default: case "0": // flat rate // don't use weight, just do flat rate for entire order // regardless of weight and regardless of the number of items $rate = $this->getRate($shipping_method_id, $product_id); break; } // if $rate->shipping_rate_id is empty, then no real rate was found if (!empty($rate->shipping_rate_id)) { $rate_exists = true; } } break; default: // throw new Exception(JText::_( "Invalid Shipping Method Type" )); return false; break; } if (!$rate_exists) { // throw new Exception( JText::_( "No Rate Found" ) ); return false; } $shipping_tax_rates = array(); $shipping_method_price = 0; $shipping_method_handling = 0; $shipping_method_tax_total = 0; // now calc for the entire method /* foreach ($geozone_rates as $geozone_id=>$geozone_rate_array) { foreach ($geozone_rate_array as $geozone_rate) { $shipping_method_price += ($geozone_rate->shipping_rate_price * $geozone_rate->qty); $shipping_method_handling += $geozone_rate->shipping_rate_handling; } } */ // return formatted object // print_r($rate); $return->shipping_method_price = $rate->shipping_rate_price; $return->shipping_method_handling = $rate->shipping_rate_handling; $return->shipping_method_total = $rate->shipping_rate_price + $rate->shipping_rate_handling; $return->shipping_method_id = $shipping_method_id; $return->shipping_method_name = K2StoreShipping::getShippingName($shipping_method_id); return $return; }
/** * * Returns an object with the total cost of shipping for this method and the array of geozones * * @param unknown_type $shipping_method_id * @param array $geozones * @param unknown_type $orderItems * @param unknown_type $order_id */ protected function getTotal($shipping_method_id, $geozones, $orderItems, $geozones_taxes) { $return = new JObject(); $return->shipping_price = '0.00000'; $return->shipping_handling = '0.00000'; $return->shipping_tax_total = '0.00000'; $rate_exists = false; $geozone_rates = array(); // determine the shipping method type $this->includeCustomTables('shipping_weightbased'); $shippingmethod = JTable::getInstance('ShippingMethodsWeightbased', 'TiendaTable'); $shippingmethod->load($shipping_method_id); if (empty($shippingmethod->shipping_method_weightbased_id)) { // TODO if this is an object, setError, otherwise return false, or 0.000? $return->setError(JText::_('COM_TIENDA_UNDEFINED_SHIPPING_METHOD')); return $return; } $sum_weight = $this->calculateWeight($orderItems); $order_ships = $sum_weight != 0; if ($order_ships) { foreach ($geozones as $geozone) { unset($rate); $geozone_id = $geozone->geozone_id; if (empty($geozone_rates[$geozone_id]) || !is_array($geozone_rates[$geozone_id])) { $geozone_rates[$geozone_id] = array(); } // get the shipping rate for the entire order using the sum weight of all products in the order that ship $rate = $this->getRate($shipping_method_id, $geozone_id, $sum_weight); // if $rate->shipping_rate_id is empty, then no real rate was found if (!empty($rate->shipping_rate_weightbased_id)) { $rate_exists = true; $geozone_rates[$geozone_id]['0'] = $rate; } } } if (!$rate_exists) { $this->setError(JText::_('COM_TIENDA_NO_RATE_FOUND')); return false; } $shipping_tax_rates = array(); $shipping_method_price = 0; $shipping_method_handling = 0; $shipping_method_tax_total = 0; // now calc for the entire method foreach ($geozone_rates as $geozone_id => $geozone_rate_array) { foreach ($geozone_rate_array as $geozone_rate) { $shipping_tax_rates[$geozone_id] = 0; foreach ($geozones_taxes as $gz_tax) { $shipping_tax_rates[$geozone_id] += $this->getTaxRate($shipping_method_id, $gz_tax->geozone_id); } $return->shipping_rate_weightbased_id = $geozone_rate->shipping_rate_weightbased_id; $rate_price = $this->calculatePriceRate($geozone_rate, $sum_weight); $shipping_method_price += $rate_price; $shipping_method_handling += $geozone_rate->shipping_handling; $shipping_method_tax_total += $shipping_tax_rates[$geozone_id] / 100 * ($rate_price + $geozone_rate->shipping_handling); } } // return formatted object $return->shipping_price = $shipping_method_price; $return->shipping_handling = $shipping_method_handling; $return->shipping_tax_rates = $shipping_tax_rates; $return->shipping_tax_total = $shipping_method_tax_total; $return->shipping_method_id = $shipping_method_id; $return->shipping_method_name = $shippingmethod->shipping_method_weightbased_name; return $return; }
function _populateDatabase(&$database, $sqlfile, &$errors) { if (!($buffer = file_get_contents($sqlfile))) { $vars = new JObject(); $vars->state = $this->_getState(); $vars->setError($this->getError()); return $this->_getLayout("view_2", $vars); } $queries = $this->_splitSql($buffer); $results = array(); $n = 0; foreach ($queries as $query) { $query = trim($query); if ($query != '' && $query[0] != '#') { $database->setQuery($query); $results[$n]->query = $database->getQuery(); $results[$n]->error = ''; if (!$database->query()) { $results[$n]->error = $database->getErrorMsg(); } $results[$n]->affectedRows = $database->getAffectedRows(); $n++; } } return $results; }