Jump to content

freeshipping info in cart module PS 1.5.6.0 to 16.1.8


Recommended Posts

please help with this module in version 1.5 works

post-737778-0-40112400-1479123435_thumb.png

in version 1.6.1.8 but not where the error

	public function displayProductButtons($params) {
    global $errors;
		/* @var $product ProductCore */
		$product = $params['product'];
	
		/* @var $cookie CookieCore */
		$cookie = $params['cookie'];
		
		$id_currency = (int) $cookie->id_currency;
		$id_lang =  (int) $cookie->id_lang ;
		
		$id_zone = $this->getZoneFromLoggedUser();
		if($id_zone == false){
			$lang_isoCode = Language::getIsoById( $id_lang );

			if(isset($this->langCarriersMap[$lang_isoCode])){
				$id_zone = Zone::getIdByName($this->langCarriersMap[$lang_isoCode]);
			}else{
				$id_zone = Zone::getIdByName($this->defaultZone);
			}
		}
			
		$carriers = Carrier::getCarriersForOrder($id_zone);
		$lowestShipping = false;
		foreach($carriers as $carrierAr){
			if($carrierAr['name'] == $this->personalPickUp)
				continue;
			
			/* @var $carrier CarrierCore */
			$carrier = new CarrierCore($carrierAr['id_carrier'], $id_lang);
	
			$shipping = $carrier->getDeliveryPriceByPrice($product->getPrice(), $id_zone, $id_currency);
			if($lowestShipping == true || $shipping < $lowestShipping){
				$lowestShipping = $shipping;

				if($lowestShipping == 0){
					break;
				}
			}
		}
		
		$freeShipping = ($lowestShipping !== false && $lowestShipping == 0 ? true :false);
		
		$this->context->smarty->assign(
			array(
				'freeShipping' => $freeShipping
			));
	
		return $this->display(__FILE__, 'product.tpl');
    
	}
	
	/**
	 * Vypočítá jakou částku ej nutné přidat do kočíku pro dopravu zdarma, podle aktuálně zvoleného jazyka
	 * @return int
	 */
	public function getFreeShippingLeft() {	
		$id_lang =  (int) $this->context->cookie->id_lang ;
		$id_zone = $this->getZoneFromLoggedUser();
		if($id_zone == false){
			$lang_isoCode = Language::getIsoById( $id_lang );
			if(isset($this->langCarriersMap[$lang_isoCode])){
				$id_zone = Zone::getIdByName($this->langCarriersMap[$lang_isoCode]);
			}else{
				$id_zone = Zone::getIdByName($this->defaultZone);
			}
		}
			
		$carriers = Carrier::getCarriersForOrder($id_zone);
		
		//nejnižší hranice pro dopravu zdarma
		$lowestLimit = FALSE;
		foreach($carriers as $carrierAr){
			if($carrierAr['name'] == $this->personalPickUp)
				continue;
			
			/* @var $carrier CarrierCore */
			$carrier = new Carrier($carrierAr['id_carrier'], $id_lang);
			
			//ranges 
			$priceRanges = $carrier->getRangeObject();
			if(!$priceRanges instanceof RangePriceCore)
				continue;;
				
			$ranges = $priceRanges->getRanges($carrierAr['id_carrier']);
			$rangesPrice = CarrierCore::getDeliveryPriceByRanges($carrier->getRangeTable(), $carrierAr['id_carrier']);
			$rangeIdPrice = array();
			//vytvoří pole id=>cena pro snažší dohledávání ceny
			foreach($rangesPrice as $range){
				if($range['id_zone'] == $id_zone)
					$rangeIdPrice[$range['id_range_price']] = $range['price'];
			}
			//projde všechny rozsahy, pokud je doprava = 0, pokusí se zapsat dolní hranici rozsahu jako nejnžší
			foreach($ranges as $range){
				$shippingPrice = $rangeIdPrice[$range['id_range_price']];
				if($shippingPrice == 0){
					if($lowestLimit === FALSE ||  $range['delimiter1'] < $lowestLimit)
					$lowestLimit = $range['delimiter1'];
				}
			}
		}
		
		//celková cena objednávky bez poštovného
		$taxCalculationMethod = Group::getPriceDisplayMethod((int)Group::getCurrent()->id);
		$useTax = !($taxCalculationMethod == PS_TAX_EXC);
		$totalToPay = $this->context->cart->getOrderTotal($useTax, Cart::BOTH_WITHOUT_SHIPPING);
		
		//cena za dopravu převedená do aktuální měny
		$shipping = Tools::convertPrice($lowestLimit, $this->context->currency, $this->context->currency->getDefaultCurrency());
		  
		//zbývá do dopravy zdarma
		return $shipping - $totalToPay;
	}
}               

post-737778-0-40112400-1479123435_thumb.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...