0

我对每个产品的选项名称进行了动态更改。问题是我正在写表更改。oc_product_option

通过转到 system/library/cart.php > public function getProducts() { },那里只加载了 product_option_value。我想在 system/library/cart.php > public function getProducts() { } 中加载此代码

然后在目录/controller/common>cart.php中调用

$data['options'] = array();

    foreach ($this->model_catalog_product->getProductOptions($this->request->get['product_id']) as $option) {
        $product_option_value_data = array();

        foreach ($option['product_option_value'] as $option_value) {
            if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
                if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
                    $price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
                } else {
                    $price = false;
                }

                $product_option_value_data[] = array(
                    'product_option_value_id' => $option_value['product_option_value_id'],
                    'option_value_id'         => $option_value['option_value_id'],
                    'name'                    => $option_value['name'],
                    'ob_info'                    => $option_value['ob_info'],
                    'image'                   => $this->model_tool_image->onesize($option_value['image'], 100, 100),
                    'price'                   => $price,
                    'price_prefix'            => $option_value['price_prefix']
                );
            }
        }

        $data['options'][] = array(
            'product_option_id'    => $option['product_option_id'],
            'product_option_value' => $product_option_value_data,
            'option_id'            => $option['option_id'],
            'name'                 => $option['name'],
            'type'                 => $option['type'],
            'value'                => $option['value'],
            'required'             => $option['required']
        );
    }

表img:http: //imgur.com/a/A9Ibw

我想这样做是因为当我添加产品时,它不会保留更改后的名称,而是使用选项的名称,因此动态名称不会检测到它。

4

1 回答 1

0

请在 catalog/model/catalog/product.php 中进行如下更改

公共函数 getProductOptions($product_id) { $product_option_data = array();

    $product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN " . DB_PREFIX . "option_description od ON (o.option_id = od.option_id) WHERE po.product_id = '" . (int)$product_id . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY o.sort_order");

    foreach ($product_option_query->rows as $product_option) {
        $product_option_value_data = array();

        $product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_id = '" . (int)$product_id . "' AND pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY ov.sort_order");

        foreach ($product_option_value_query->rows as $product_option_value) {
            $product_option_value_data[] = array(
                'product_option_value_id' => $product_option_value['product_option_value_id'],
                'option_value_id'         => $product_option_value['option_value_id'],
                'name'                    => $product_option_value['name'],
                'image'                   => $product_option_value['image'],
                'quantity'                => $product_option_value['quantity'],
                'subtract'                => $product_option_value['subtract'],
                'price'                   => $product_option_value['price'],
                'price_prefix'            => $product_option_value['price_prefix'],
                'weight'                  => $product_option_value['weight'],
                'weight_prefix'           => $product_option_value['weight_prefix']
            );
        }

        $product_option_data[] = array(
            'product_option_id'    => $product_option['product_option_id'],
            'product_option_value' => $product_option_value_data,
            'option_id'            => $product_option['option_id'],
            'name'                 => $product_option['name'],
            'dynamicname'          => $product_option['dynamicname'],
            'type'                 => $product_option['type'],
            'value'                => $product_option['value'],
            'required'             => $product_option['required']
        );
    }

    return $product_option_data;
}

之后,您可以在控制器中获取动态名称,如下所示

$data['options'] = array();

foreach ($this->model_catalog_product->getProductOptions($this->request->get['product_id']) as $option) {
    $product_option_value_data = array();

    foreach ($option['product_option_value'] as $option_value) {
        if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
            if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
                $price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
            } else {
                $price = false;
            }

            $product_option_value_data[] = array(
                'product_option_value_id' => $option_value['product_option_value_id'],
                'option_value_id'         => $option_value['option_value_id'],
                'name'                    => $option_value['name'],
                'ob_info'                    => $option_value['ob_info'],
                'image'                   => $this->model_tool_image->onesize($option_value['image'], 100, 100),
                'price'                   => $price,
                'price_prefix'            => $option_value['price_prefix']
            );
        }
    }

    $data['options'][] = array(
        'product_option_id'    => $option['product_option_id'],
        'product_option_value' => $product_option_value_data,
        'option_id'            => $option['option_id'],
        'name'                 => $option['name'],
        'dynamicname'          => $option['dynamicname'],
        'type'                 => $option['type'],
        'value'                => $option['value'],
        'required'             => $option['required']
    );
}
于 2017-07-09T17:01:33.447 回答