Your IP : 18.191.254.139


Current Path : /home/bitrix/ext_www/klimatlend.ua/bitrix/modules/sale/lib/delivery/extra_services/
Upload File :
Current File : /home/bitrix/ext_www/klimatlend.ua/bitrix/modules/sale/lib/delivery/extra_services/checkbox.php

<?php

namespace Bitrix\Sale\Delivery\ExtraServices;

use Bitrix\Main\SystemException;
use Bitrix\Main\Localization\Loc;

Loc::loadMessages(__FILE__);

class Checkbox extends Base
{
	public function __construct($id, array $structure, $currency, $value = null, array $additionalParams = array())
	{
		$structure["PARAMS"]["ONCHANGE"] = $this->createJSOnchange($id, $structure["PARAMS"]["PRICE"]);
		parent::__construct($id, $structure, $currency, $value, $additionalParams);
		$this->params["TYPE"] = "Y/N";
	}

	public function getClassTitle()
	{
		return Loc::getMessage("DELIVERY_EXTRA_SERVICE_CHECKBOX_TITLE");
	}

	public function getCost()
	{
		if($this->value == "Y")
			$result = $this->getPrice();
		else
			$result = 0;

		return $result;
	}

	public static function getAdminParamsName()
	{
		return Loc::getMessage("DELIVERY_EXTRA_SERVICE_CHECKBOX_PRICE");
	}

	public static function getAdminParamsControl($name, array $params, $currency = "")
	{
		return \Bitrix\Sale\Internals\Input\Manager::getEditHtml(
			$name."[PARAMS][PRICE]",
			array(
				"TYPE" => "NUMBER"
			),
			$params["PARAMS"]["PRICE"]
		).(strlen($currency) > 0 ? " (".$currency.")" : "");
	}

	public function setOperatingCurrency($currency)
	{
		$this->params["ONCHANGE"] = $this->createJSOnchange($this->id, $this->getPrice());
		parent::setOperatingCurrency($currency);
	}

	protected function createJSOnchange($id, $price)
	{
		$price = roundEx(floatval($price), SALE_VALUE_PRECISION);
		return "BX.onCustomEvent('onDeliveryExtraServiceValueChange', [{'id' : '".$id."', 'value': this.checked, 'price': this.checked ? '".$price."' : '0'}]);";
	}

}