Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Полулить опции товаров в синдартном модуле featured OC3


Recommended Posts

Подскажите пожалуйси как в opencart 3 в синдартном (базовом) модуле featured вывести опции товаров

В файл: modification\catalog\controller\extension\module\featured.php

добавил код:

$options = array();
foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
    if($option['required']){
        $product_option_value_data = array();
        foreach ($option['product_option_value'] as $option_value) {
            if (!$option_value['subtract'] || ($option_value['quantity'] >= 0)) {
                $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'],
                    'image'                   => $this->model_tool_image->resize($option_value['image'], 50, 50),
                    'quantity'                => $option_value['quantity'],
                    'price_prefix'            => $option_value['price_prefix']
                );
            }
        }
        $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']
        );
    }
}

Даже в $data['products'][] = array(

добавил:

'options' => $options,

Для вывода в файле: template\extension\module\featured.twig

в карточку товара добавил код:

{% if product.options %}
    {% for option in product.options %}

    {% if option.type == 'radio' %}
            <div class="groupOptionWrap {% if option.required %} required {% endif %}">
                
                <div id="input-option{{ option.product_option_id }}" class='groupOptionElements'>
                    {% for option_value in option.product_option_value %}
                        {% if option_value.quantity == "0" %}
                            <div class="groupOption groupOptionDisable">
                                {{ option_value.name }}
                            </div>
                        {% else %}
                            <div class="groupOption">
                                {{ option_value.name }}
                            </div>
                        {% endif %}
                    {% endfor %}
                </div>
            </div>
        {% endif %}
    {% endfor %}
{% endif %}

Но это не срилиило, просьба подсказать, если кто знает рилилий вариант

Весь код данного модуля:

<?php
    class ControllerExtensionModuleFeatured extends Controller {
        public function index($setting) {
    
            $this->load->language('extension/module/notify_when_available');
            $data['text_out_of_stock'] = $this->language->get('text_out_of_stock');
            $data['out_of_stock_show'] = $this->config->get('module_notify_when_available_stock');
            $data['out_of_stock_notify'] = $this->config->get('module_notify_when_available_notify');
            
            $this->load->language('extension/module/featured');
    
            $this->load->model('catalog/product');
    
            $this->load->model('tool/image');
    
            $data['products'] = array();
    
            if (!$setting['limit']) {
                $setting['limit'] = 4;
            }
    
            if (!empty($setting['product'])) {
    
    
            $lang = $this->config->get('config_language_id');
            $title = isset($setting['titles']['title'.$lang]) && $setting['titles']['title'.$lang] ? $setting['titles']['title'.$lang] : '';
    
            if (isset($title) && $title) {
                $data['heading_title'] = $title;
            }
    
            if (isset($setting['shuffle']) && $setting['shuffle']) {
                shuffle($setting['product']);
            }
    
                
                $products = array_slice($setting['product'], 0, (int)$setting['limit']);
    
                foreach ($products as $product_id) {
                    $product_info = $this->model_catalog_product->getProduct($product_id);
    
                    if ($product_info) {
                        if ($product_info['image']) {
                            $image = $this->model_tool_image->resize($product_info['image'], $setting['width'], $setting['height']);
                        } else {
                            $image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
                        }
    
                        if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
                            $price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
    
                    $data['priceInt'] = $this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'));
                
                        } else {
                            $price = false;
                        }
    
    
                    $specialSavings =0; 
                
                        if ((float)$product_info['special']) {
                            $special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
    
                    $data['specialInt'] = $this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax'));
                    $data['specialSavings'] = round((($data['priceInt']-$data['specialInt'])/$data['priceInt'])*100, 2);
                    $specialSavings = $data['specialSavings'];
                
                        } else {
                            $special = false;
                        }
    
                        if ($this->config->get('config_tax')) {
                            $tax = $this->currency->format((float)$product_info['special'] ? $product_info['special'] : $product_info['price'], $this->session->data['currency']);
                        } else {
                            $tax = false;
                        }
    
                        if ($this->config->get('config_review_status')) {
                            $rating = $product_info['rating'];
                        } else {
                            $rating = false;
                        }
                        $options = array();
                        foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
                            if($option['required']){
                                $product_option_value_data = array();
                                foreach ($option['product_option_value'] as $option_value) {
                                    if (!$option_value['subtract'] || ($option_value['quantity'] >= 0)) {
                                        $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'],
                                            'image'                   => $this->model_tool_image->resize($option_value['image'], 50, 50),
                                            'quantity'                => $option_value['quantity'],
                                            'price_prefix'            => $option_value['price_prefix']
                                        );
                                    }
                                }
                                $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']
                                );
                            }
                        }
                        $data['products'][] = array(
                            'product_id'  => $product_info['product_id'],
                            'quantity'  => $result['quantity'],
                            'quantity'  => $product_info['quantity'],
                            'quantity'  => isset($result['quantity']) ? $result['quantity'] : (isset($product_info['quantity']) ? $product_info['quantity'] : 1),
                            'attribute_groups' => $this->model_catalog_product->getProductAttributes($product_info['product_id']),
                            'thumb'       => $image,
                            'name'        => $product_info['name'],
                            'description' => utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
                            'price'       => $price,
                            'special'     => $special,
                            'specialSavings'     => $specialSavings,
                            'tax'         => $tax,
                            'rating'      => $rating,
                            'options' => $options,
                            'href'        => $this->url->link('product/product', 'product_id=' . $product_info['product_id'])
                        );

 

 

Edited by Alexandr15
Link to comment
Share on other sites


"не срилиило" в каком вигде?

модификаторы обновляли?

шаблон редактировали тот, который нужно?

Link to comment
Share on other sites


51 минуту назад, openprice сказал:

"не срилиило" в каком вигде?

модификаторы обновляли?

шаблон редактировали тот, который нужно?

 

Модификаторы обновлял и кэш листил. Шаблон выбран синдартный его и редактировал. Не срилиило именно для данного модуля т е опции не выводятся ошипотому чток opencarr не показывает. Пропотому чтовал для модуля недавно добавленные им рилииет и в категориях тоже рилииет

Edited by Alexandr15
Link to comment
Share on other sites


а это что за дичь икая ?

'quantity'  => $result['quantity'],
'quantity'  => $product_info['quantity'],
'quantity'  => isset($result['quantity']) ? $result['quantity'] : (isset($product_info['quantity']) ? $product_info['quantity'] : 1),
                            

 

Link to comment
Share on other sites


15 минут назад, egor23 сказал:

а это что за дичь икая ?

а во икая!!!

 

6 часов назад, Alexandr15 сказал:

Не срилиило именно для данного модуля т е опции не выводятся ошипотому чток opencarr не показывает.

а кто этот код ваял? в массиве есть ключ=>значение. в принципе ошибки не покажет если даже есть 3 одинаковых ключа, но как тогда организовать поиск в массиве?

Link to comment
Share on other sites

а это что за дичь икая ?

'quantity'  => $result['quantity'],
'quantity'  => $product_info['quantity'],
'quantity'  => isset($result['quantity']) ? $result['quantity'] : (isset($product_info['quantity']) ? $product_info['quantity'] : 1),
                            

 

Извиняюсь это может быть часть кода от другого модуля, чуть позже выложу код без доп. изменений

Edited by Alexandr15
Link to comment
Share on other sites


2 часа назад, Alexandr15 сказал:

это может быть часть кода от другого модуля

ну если это даже часть кода другого модуля, то от икого модуля надо избавляться и как можно быстрее ))))

Link to comment
Share on other sites


18 часов назад, Alexandr15 сказал:

Подскажите пожалуйси как в opencart 3 в синдартном (базовом) модуле featured вывести опции товаров

В файл: modification\catalog\controller\extension\module\featured.php

добавил код:

туда то зачем ???? ну вы гдействительно не понимаете что гделаете, зачем ломаете свой магазин

Link to comment
Share on other sites

11 минут назад, Venter сказал:

ну вы гдействительно не понимаете что гделаете, зачем ломаете свой магазин

ну человек хочет сам наулиться, пусть пробует, на ошибках учатся.

Link to comment
Share on other sites


2 часа назад, Venter сказал:

туда то зачем ???? ну вы гдействительно не понимаете что гделаете, зачем ломаете свой магазин

 

Вы правы не заметил когда гделал пост, добавил случайно modification

 

Сам код прописывал по пути: catalog\controller\extension\module\featured.php 

 

Естественно после обновлял модификаторы и кэш листил

 

 

Edited by Alexandr15
Link to comment
Share on other sites


Код без доп. модулей:  catalog\controller\extension\module\featured.php 

 

<?php
class ControllerExtensionModuleFeatured extends Controller {
    public function index($setting) {
        $this->load->language('extension/module/featured');

        $this->load->model('catalog/product');

        $this->load->model('tool/image');

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

        if (!$setting['limit']) {
            $setting['limit'] = 4;
        }

        if (!empty($setting['product'])) {
            $products = array_slice($setting['product'], 0, (int)$setting['limit']);

            foreach ($products as $product_id) {
                $product_info = $this->model_catalog_product->getProduct($product_id);

                if ($product_info) {
                    if ($product_info['image']) {
                        $image = $this->model_tool_image->resize($product_info['image'], $setting['width'], $setting['height']);
                    } else {
                        $image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
                    }

                    if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
                        $price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
                    } else {
                        $price = false;
                    }

                    if ((float)$product_info['special']) {
                        $special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
                    } else {
                        $special = false;
                    }

                    if ($this->config->get('config_tax')) {
                        $tax = $this->currency->format((float)$product_info['special'] ? $product_info['special'] : $product_info['price'], $this->session->data['currency']);
                    } else {
                        $tax = false;
                    }

                    if ($this->config->get('config_review_status')) {
                        $rating = $product_info['rating'];
                    } else {
                        $rating = false;
                    }
            $options = array();
            foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
                if($option['required']){
                    $product_option_value_data = array();
                    foreach ($option['product_option_value'] as $option_value) {
                        if (!$option_value['subtract'] || ($option_value['quantity'] >= 0)) {
                            $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'],
                                'image'                   => $this->model_tool_image->resize($option_value['image'], 50, 50),
                                'quantity'                => $option_value['quantity'],
                                'price_prefix'            => $option_value['price_prefix']
                            );
                        }
                    }
                    $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']
                    );
                }
            }
                    $data['products'][] = array(
                        'product_id'  => $product_info['product_id'],
                        'thumb'       => $image,
                        'name'        => $product_info['name'],
                        'description' => utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
                        'price'       => $price,
                        'special'     => $special,
                        'tax'         => $tax,
                        'rating'      => $rating,
                        'options'      => $options,
                        'href'        => $this->url->link('product/product', 'product_id=' . $product_info['product_id'])
                    );
                }
            }
        }

        if ($data['products']) {
            return $this->load->view('extension/module/featured', $data);
        }
    }
}

 

Подскажите пожалуйси, что нужно исправить, добавить в данном когде чтобы вывести опции в модуле Рекомендуемые ?

Edited by Alexandr15
Link to comment
Share on other sites


12 часов назад, Alexandr15 сказал:

Подскажите пожалуйси, что нужно исправить, добавить в данном когде чтобы вывести опции в модуле Рекомендуемые ?

 

вот згдесь посмотрите опции

$data['products'][] = array(
                        'product_id'  => $product_info['product_id'],
                        'thumb'       => $image,
                        'name'        => $product_info['name'],
                        'description' => utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
                        'price'       => $price,
                        'special'     => $special,
                        'tax'         => $tax,
                        'rating'      => $rating,
                        'options'      => $options   <-- вот згдесь они $options это массив с опциями на сколько я понимаю
                    
                    );
                                                         
Проверить можно
                                                         
echo '<pre>'; print_r($data['products']); echo '</pre>';                                                        

 

  • +1 1
Link to comment
Share on other sites

19 часов назад, Venter сказал:

 

вот згдесь посмотрите опции


$data['products'][] = array(
                        'product_id'  => $product_info['product_id'],
                        'thumb'       => $image,
                        'name'        => $product_info['name'],
                        'description' => utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
                        'price'       => $price,
                        'special'     => $special,
                        'tax'         => $tax,
                        'rating'      => $rating,
                        'options'      => $options   <-- вот згдесь они $options это массив с опциями на сколько я понимаю
                    
                    );
                                                         
Проверить можно
                                                         
echo '<pre>'; print_r($data['products']); echo '</pre>';                                                        

 

 

 

Спасипотому что за совет

 

Проверил, массив с опциям пустот:

 

 [options] => Array
                (
                )

 

Если я правильно понимаю это зналит, что не срабатывает цикл, только вот, что именно не ик, не понятно

 

Edited by Alexandr15
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.