public function addShippingCosts($shippingId = 0, $paymentId = 0)
{
//$app = JFactory::getApplication();
if ($shippingId == 0) {
$shippingId = $this->shipping['id'];
}
$shippingObject = new PhocacartShipping();
$shippingObject->setType($this->type);
$sI = $shippingObject->getShippingMethod((int) $shippingId);
if (!isset($this->total[0])) {
$this->total[0] = array();
}
$shippingValid = $shippingObject->checkAndGetShippingMethod((int) $shippingId, $this->total[0]);
if (!$shippingValid) {
PhocacartShipping::removeShipping();
// In case user has in cart shipping method which does not exists
// Wait for payment costs
//PhocacartPayment::removePayment();// It does not remove payment immediately (but after reload) or when ordering (order tests the conditions)
//$app->enqueueMessage(JText::_('COM_PHOCACART_NO_SHIPPING_METHOD_FOUND'));
unset($sI);
}
if (!empty($sI)) {
$sI->freeshipping = 0;
if (isset($this->total[0]['free_shipping']) && $this->total[0]['free_shipping'] == 1) {
$sI->freeshipping = 1;
}
$price = new PhocacartPrice();
$priceI = $price->getPriceItemsShipping($sI->cost, $sI->cost_additional, $sI->calculation_type, $this->total[0], $sI->taxid, $sI->taxrate, $sI->taxcalculationtype, $sI->taxtitle, $sI->freeshipping, 1);
// CALCULATION
$calc = new PhocacartCartCalculation();
$calc->setType($this->type);
$this->shipping['costs'] = $priceI;
if (!isset($this->total[0]['free_shipping']) || isset($this->total[0]['free_shipping']) && $this->total[0]['free_shipping'] != 1) {
$this->shipping['costs']['id'] = $sI->id;
$this->shipping['costs']['title'] = $sI->title;
$this->shipping['costs']['title_lang'] = $sI->title;
$this->shipping['costs']['title_lang_suffix'] = '';
$this->shipping['costs']['title_lang_suffix2'] = '';
$this->shipping['costs']['description'] = $sI->description;
$this->shipping['costs']['image'] = $sI->image;
$this->shipping['costs']['method'] = $sI->method;
$this->shipping['costs']['params_shipping'] = !empty($this->shipping['params_shipping']) ? $this->shipping['params_shipping'] : array();
// Update even the shipping info
$this->shipping['id'] = $sI->id;
$this->shipping['title'] = $sI->title;
$this->shipping['method'] = $sI->method;
$this->shipping['image'] = $sI->image;
}
$calc->calculateShipping($priceI, $this->total[0]);
//$calc->round($this->total[0], 0);
}
}