Пример #1
0
function smartyModifierPPSafeoutputLenient($string, $type = null)
{
    if ($type === null) {
        $type = 'html';
    }
    switch ($type) {
        case 'html':
            return PP::safeOutputLenient($string);
        case 'js':
        case 'javascript':
            return PP::safeOutputLenientJS($string);
        case 'value':
            return PP::safeOutputLenientValue($string);
        default:
            return $string;
    }
}
Пример #2
0
    public function hookDisplayPpropertiesProduct($params)
    {
        if (!$this->integrated) {
            return;
        }
        $product = $params['product'];
        if (!Validate::isLoadedObject($product)) {
            return;
        }
        $has_discounts = isset($params['ppDiscounts']) && (bool) $params['ppDiscounts'];
        $product_properties = $product->productProperties();
        $pp_product_properties = array();
        $quotes = array();
        foreach ($product_properties as $key => $value) {
            if (strpos($key, 'pp_') === 0 && strpos($key, 'pp_bo_') !== 0 && strpos($key, '_text') > 0) {
                $pp_product_properties[$key] = $value;
                $quotes[$key] = true;
            }
        }
        foreach ($this->getTranslations('ProductController') as $key => $value) {
            $pp_product_properties[$key] = $value;
            $quotes[$key] = true;
        }
        $pp_product_properties = PP::safeOutputJS($pp_product_properties);
        $pp_product_properties['id_pp_template'] = $product_properties['id_pp_template'];
        $pp_product_properties['pp_qty_policy'] = $product_properties['pp_qty_policy'];
        $pp_product_properties['pp_display_mode'] = $product_properties['pp_display_mode'];
        $pp_product_properties['pp_price_display_mode'] = $product_properties['pp_price_display_mode'];
        $pp_product_properties['pp_minimal_price_ratio'] = $product_properties['pp_minimal_price_ratio'];
        $pp_product_properties['pp_qty_step'] = $product_properties['pp_qty_step'];
        $pp_product_properties['minQty'] = $product->minQty();
        $pp_product_properties['defaultQty'] = isset($this->context->smarty->tpl_vars['quantityBackup']) ? $this->context->smarty->tpl_vars['quantityBackup'] : $product->defaultQty();
        $pp_product_properties['explanation'] = PP::safeOutputLenientJS($product_properties['pp_explanation']);
        $quotes['explanation'] = true;
        $pp_product_properties['pp_css'] = PP::safeOutputJS($product_properties['pp_css']);
        $quotes['pp_css'] = true;
        if ((int) (($product_properties['pp_display_mode'] & 2) == 2)) {
            $pp_product_properties['display_mode_retail_price'] = Product::getRetailPrice($product);
        }
        if (!$this->multidimensional_plugin) {
            $product_properties['pp_ext'] = 0;
        }
        $pp_product_properties['pp_ext'] = $product_properties['pp_ext'];
        $script = '
		<script type="text/javascript">
			$("body").addClass("' . $product_properties['pp_css'] . ' pp_template_' . $product_properties['id_pp_template'] . (Configuration::get('PP_SHOW_POSITIONS') ? ' pp-positions-visible' : '') . '");
			var ppProductProperties = [];';
        foreach ($pp_product_properties as $key => $value) {
            if (isset($quotes[$key])) {
                $value = '"' . $value . '"';
            }
            $script .= '
			ppProductProperties["' . $key . '"] = ' . $value . ';';
        }
        if ($product_properties['pp_ext'] == 1) {
            $script .= '
			ppProductProperties["pp_ext_policy"] = ' . $product_properties['pp_ext_policy'] . ';';
            $script .= '
			ppProductProperties["pp_ext_method"] = ' . $product_properties['pp_ext_method'] . ';';
            $script .= '
			ppProductProperties["pp_ext_title"] = "' . PP::safeOutputLenientJS($product_properties['pp_ext_title']) . '";';
            $script .= '
			ppProductProperties["pp_ext_property"] = "' . PP::safeOutputLenientJS($product_properties['pp_ext_property']) . '";';
            $script .= '
			ppProductProperties["pp_ext_text"] = "' . PP::safeOutputLenientJS($product_properties['pp_ext_text']) . '";';
            $script .= '
			ppProductProperties["pp_ext_prop"] = [];';
            foreach ($product_properties['pp_ext_prop'] as $position => $arr) {
                $s = '{';
                $s .= 'property:"' . PP::safeOutputLenientJS($arr['property']) . '"';
                $s .= ',text:"' . PP::safeOutputLenientJS($arr['text']) . '"';
                $s .= ',minimum_quantity:' . (double) $arr['minimum_quantity'];
                $s .= ',maximum_quantity:' . (double) $arr['maximum_quantity'];
                $s .= ',default_quantity:' . (double) $arr['default_quantity'];
                $s .= ',qty_step:' . (double) $arr['qty_step'];
                $s .= ',qty_ratio:' . (double) $arr['qty_ratio'];
                $s .= '}';
                $script .= '
				ppProductProperties["pp_ext_prop"][' . $position . '] = ' . $s . ';';
            }
            if ($product_properties['pp_ext_policy'] == 2) {
                $script .= '
				ppProduct.fallback_ext_quantity = 1;
				ppProduct.prop = ' . Tools::jsonEncode($product->productProp()) . ';';
            }
        }
        $actions = array('price' => $this->context->link->getModuleLink($this->name, 'product', array('process' => 'price')));
        $script .= '
			ppProduct.actions = ' . Tools::jsonEncode($actions) . ';
			ppProduct.hasAttributes = ' . ($product->hasAttributes() ? 'true' : 'false') . ';
			ppProduct.priceObserver = ' . ($has_discounts || PSM::getPlugin('ppropertiessmartprice') ? 'true' : 'false') . ';';
        $script .= '
		</script>';
        return $script;
    }