意外的T_STRING,但在哪里?

时间:2016-04-12 11:30:21

标签: php prestashop

我正在做一个prestashop模块(我昨天发布了其他问题)。我想现在我遇到了PHP的问题。每次它都告诉我行if($same_puente === false OR $same_patilla === false)...解析错误:语法错误,该行中的意外T_STRING。

<?php

if (!defined('_PS_VERSION_'))
    exit;

class glassOptics extends Module
{
    /* @var boolean error */
    protected $_errors = false;

    /* @var boolean puente */
    public $same_puente = false;

    /* @var boolean patilla */
    public $same_patilla = false;

    /* @var boolean altura cristal */
    public $same_altura_cristal = false;

    /* @var boolean ancho cristal */
    public $same_ancho_cristal = false;

    public function __construct()
    {
        $this->name = 'glassOptics';
        $this->tab = 'front_office_features';
        $this->version = '1.0';
        $this->author = 'Víctor Martín';
        $this->need_instance = 0;

        parent::__construct();

        $this->displayName = $this->l('glassOptics');
        $this->description = $this->l('Módulo para Ópticas, de filtrado de gafas compatibles para cada cliente.');
    }

    public function install()
    {
        if (!parent::install() OR
            !$this->glopticasCustomerDB('add') OR
            !$this->glopticasProductDB('add') OR
            !$this->glopticasProductLangDB('modify') OR         
            !$this->registerHook('hookActionProductListOverride') OR            
            !$this->registerHook('DisplayAdminProductsExtra') OR            
            !$this->registerHook('ActionProductUpdate'))
            return false;
        return true;
    }

    public function uninstall()
    {
        if (!parent::uninstall() OR !$this->glopticasCustomerDB('remove') OR !$this->glopticasProductDB('remove'))
            return false;
        return true;
    }


    public function glopticasCustomerDB($method)
    {
        switch ($method) {
            case 'add': 

                $decimal_zero = '0.000000';
                $decimal_zero = mysql_real_escape_string($decimal_zero);

                $sql = 'CREATE TABLE IF EXISTS `'._DB_PREFIX_.'customer_optics_data` (
                `id_customer` int(10) UNSIGNED NOT NULL,
                `dioptrias_izquierdo` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `dioptrias_derecho` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `puente` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `patilla` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `altura_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `ancho_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.'
                ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';

                break;

            case 'remove':
                $sql = 'DROP TABLE IF EXISTS `'._DB_PREFIX_ . 'customer_optics_data`';
                break;
        }

        if(!Db::getInstance()->Execute($sql))
            return false;
        return true;
    }

    public function glopticasProductDB($method)
    {
        switch ($method) {
            case 'add': 

                $decimal_zero = '0.000000';
                $decimal_zero = mysql_real_escape_string($decimal_zero);

                $sql = 'CREATE TABLE IF EXISTS `'._DB_PREFIX_.'product_optics_data` (
                `id_product` int(10) UNSIGNED NOT NULL,
                `dioptrias_izquierdo` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `dioptrias_derecho` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `puente` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `patilla` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `altura_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `ancho_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.'
                ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';

                break;

            case 'remove':
                $sql = 'DROP TABLE IF EXISTS `'._DB_PREFIX_ . 'product_optics_data`';
                break;
        }

        if(!Db::getInstance()->Execute($sql))
            return false;
        return true;
    }


    public function glopticasProductLangDB($method)
    {
        switch ($method) {
            case 'modify':  

                $decimal_zero = '0.000000';
                $decimal_zero = mysql_real_escape_string($decimal_zero);

                $sql = 'ALTER TABLE ' . _DB_PREFIX_ . 'product_lang '
                .'ADD `dioptrias_izquierdo` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
                .'ADD `dioptrias_derecho` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
                .'ADD `puente` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
                .'ADD `patilla` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
                .'ADD `altura_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
                .'ADD `ancho_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.''
                .') ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';

                break;

        }

        if(!Db::getInstance()->Execute($sql))
            return false;
        return true;
    }

    public function hookActionProductListOverride($params)
    {
        $customer_settings = glassOpticsHelperClass::getCustomerSettings($this->context->customer);

        if (!is_null($customer_settings)) {
            // Inform the hook was executed
            $params['hookExecuted'] = true;

            // Filter products here, you are now overriding the default
            // functionality of CategoryController class.
            // You can see blocklayered module for more details.

            if ((isset($this->context->controller->display_column_left) && !$this->context->controller->display_column_left)
            && (isset($this->context->controller->display_column_right) && !$this->context->controller->display_column_right))
            return false;

            global $smarty;
            if (!Configuration::getGlobalValue('PS_LAYERED_INDEXED'))
                return;

            $sql_cat = 'SELECT COUNT(*) FROM '._DB_PREFIX_.'layered_category WHERE id_category = '.(int)Tools::getValue('id_category', Tools::getValue('id_category_layered', Configuration::get('PS_HOME_CATEGORY'))).'
                AND id_shop = '.(int) Context::getContext()->shop->id;
            $categories_count = Db::getInstance()->getValue($sql_cat);

            if ($categories_count == 0)
                return;

            // List of product to overrride categoryController
            $params['catProducts'] = array();
            $selected_filters = $this->getSelectedFilters();
            $filter_block = $this->getFilterBlock($selected_filters);
            $title = '';

            if (is_array($filter_block['title_values']))
                foreach ($filter_block['title_values'] as $key => $val)
                    $title .= ' > '.$key.' '.implode('/', $val);

            $smarty->assign('categoryNameComplement', $title);
            $this->getProducts($selected_filters, $params['catProducts'], $params['nbProducts'], $p, $n, $pages_nb, $start, $stop, $range);
            // Need a nofollow on the pagination links?
            $smarty->assign('no_follow', $filter_block['no_follow']);

            filterProductsByConditions($customer_settings, $params['nbProducts']);


        }
    }

    private static function filterProductsByConditions($customer_settings, $product_collection) {
        if(!is_null($product_collection)){

            foreach ($product_collection as $product){
                $product_settings = glassOpticsHelperClass::getProductSettings($product);

                if(!is_null($product_settings)){

                    if(!is_null($product_settings->puente) AND !is_null($customer_settings->puente)){
                        $same_puente = (($product_settings->puente == $customer_settings->puente) ? true : false);
                    }else{
                        $same_puente = false;
                    }

                    if(!is_null($product_settings->patilla) AND !is_null($customer_settings->patilla)){
                        $same_patilla = (($product_settings->patilla == $customer_settings->patilla) ? true : false);
                    }else{
                        $same_patilla = false;
                    }

                    if(!is_null($product_settings->altura_cristal) AND !is_null($customer_settings->altura_cristal)){
                        $same_altura_cristal = (($product_settings->altura_cristal == $customer_settings->altura_cristal) ? true : false);
                    }else{
                        $same_altura_cristal = false;
                    }

                    if(!is_null($product_settings->ancho_cristal) AND !is_null($customer_settings->ancho_cristal)){
                        $same_ancho_cristal = (($product_settings->ancho_cristal == $customer_settings->ancho_cristal) ? true : false);
                    }else{
                        $same_ancho_cristal = false;
                    }

                    if($same_puente === false OR $same_patilla === false){
                        unset($product_collection[$product]);
                    }
                }
            }
            return $product_collection;
        }else{
            return $product_collection;
        }
    }
}

我做错了什么?谢谢。

2 个答案:

答案 0 :(得分:2)

您的$sql声明中有一个额外的结束括号:.') ENGINE='._MYSQL_ENGINE_.'

$sql = 'ALTER TABLE ' . _DB_PREFIX_ . 'product_lang '
.'ADD `dioptrias_izquierdo` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
.'ADD `dioptrias_derecho` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
.'ADD `puente` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
.'ADD `patilla` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
.'ADD `altura_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
.'ADD `ancho_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.''
.') ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';

答案 1 :(得分:1)

你的问题在这里:

<td>

您必须使用foreach ($product_collection as $product){ ... unset($product_collection[$product]); } 来获取数组的元素:

$key

因为foreach ($product_collection as $key => $product){ ... unset($product_collection[$key]); } 是数组元素的值,而不是键。