Post by ianhaney50 » Thu Dec 12, 2024 5:08 pm

I'm trying to get the product options displayed on the featured module, I copied the code that is from the category pages as I got the product options displayed on the category page so thought it would be the same thing so copied the code to the relevant files but it's not showing the product options on the featured module. Below is the code I have in the relevant files. I'm using 3.0.4.0

In catalog/controller/extension/module/featured.php

Code: Select all

'options'      => $this->model_catalog_product->getProductOptions($result['product_id']),
In Catalog/view/theme/default/template/extension/module/featured.twig

Code: Select all

            {% if product.options %}
 <div id="options_div_{{ product.product_id }}">
            <h3>options</h3>
            {% for option in product.options %}
            {% if option.type == 'select' %}
            <div class="form-group{% if option.required %} required {% endif %}">
              <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
              <select name="option[{{ option.product_option_id }}]" id="input-option{{ option.product_option_id }}" class="form-control">
                <option value="">{{ text_select }}</option>
                {% for option_value in option.product_option_value %}
                {% if option_value.quantity > 0 %}
                <option value="{{ option_value.product_option_value_id }}">{{ option_value.name }}
                {% if option_value.price %}
                ({{ option_value.price_prefix }}{{ option_value.price }})
                {% endif %} </option>
                {% endif %}
                {% endfor %}
              </select>
            </div>
            {% endif %}
            {% if option.type == 'radio' %}
            <div class="form-group{% if option.required %} required {% endif %}">
              <label class="control-label">{{ option.name }}</label>
              <div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
                {% if option_value.quantity > 0 %}
                <div class="radio">
                  <label>
                    <input type="radio" name="option[{{ option.product_option_id }}]" value="{{ option_value.product_option_value_id }}" />
                    {% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}                  
                    {{ option_value.name }}
                    {% if option_value.price %}
                    ({{ option_value.price_prefix }}{{ option_value.price }})
                    {% endif %} </label>
                </div>
                {% endif %}
                {% endfor %} </div>
            </div>
            {% endif %}
            {% if option.type == 'checkbox' %}
            <div class="form-group{% if option.required %} required {% endif %}">
              <label class="control-label">{{ option.name }}</label>
              <div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
                {% if option_value.quantity > 0 %}
                <div class="checkbox">
                  <label>
                    <input type="checkbox" name="option[{{ option.product_option_id }}][]" value="{{ option_value.product_option_value_id }}" />
                    {% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
                    {{ option_value.name }}
                    {% if option_value.price %}
                    ({{ option_value.price_prefix }}{{ option_value.price }})
                    {% endif %} </label>
                </div>
                {% endif %}
                {% endfor %} </div>
            </div>
            {% endif %}
            {% if option.type == 'text' %}
            <div class="form-group{% if option.required %} required {% endif %}">
              <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
              <input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control" />
            </div>
            {% endif %}
            {% if option.type == 'textarea' %}
            <div class="form-group{% if option.required %} required {% endif %}">
              <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
              <textarea name="option[{{ option.product_option_id }}]" rows="5" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control">{{ option.value }}</textarea>
            </div>
            {% endif %}
            {% if option.type == 'file' %}
            <div class="form-group{% if option.required %} required {% endif %}">
              <label class="control-label">{{ option.name }}</label>
              <button type="button" id="button-upload{{ option.product_option_id }}" data-loading-text="{{ text_loading }}" class="btn btn-default btn-block"><i class="fa fa-upload"></i> {{ button_upload }}</button>
              <input type="hidden" name="option[{{ option.product_option_id }}]" value="" id="input-option{{ option.product_option_id }}" />
            </div>
            {% endif %}
            {% if option.type == 'date' %}
            <div class="form-group{% if option.required %} required {% endif %}">
              <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
              <div class="input-group date">
                <input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD" id="input-option{{ option.product_option_id }}" class="form-control" />
                <span class="input-group-btn">
                <button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button>
                </span></div>
            </div>
            {% endif %}
            {% if option.type == 'datetime' %}
            <div class="form-group{% if option.required %} required {% endif %}">
              <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
              <div class="input-group datetime">
                <input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
                <span class="input-group-btn">
                <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                </span></div>
            </div>
            {% endif %}
            {% if option.type == 'time' %}
            <div class="form-group{% if option.required %} required {% endif %}">
              <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
              <div class="input-group time">
                <input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
                <span class="input-group-btn">
                <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                </span></div>
            </div>
            {% endif %}
            {% endfor %}
     
     <div class="button-group one mb-3">
                                    <input type="text" name="quantity" value="{{ product.minimum }}" size="2" id="input-quantity" class="form-control" />
                                </div>
     
     {% if product.price %}
            <p class="price">
                {% if not product.special %}
                {{ product.price }}
                {% else %}
                <span class="price-new">{{ product.special }}</span> <span class="price-old">{{ product.price }}</span>
                {% endif %}
                {% if product.tax %}
                <span class="price-tax">{{ text_tax }} {{ product.tax }}</span>
                {% endif %}
            </p>
            {% endif %}
     
     <div class="button-group one">
                                <input type="hidden" name="product_id" value="{{ product.product_id }}" />
                                <button type="button" class="one" id="button-cart_{{ product.product_id }}" data-loading-text="{{ text_loading }}"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md">{{ button_cart }}</span></button>
                            </div>
            </div>
            {% else %}
            
            {% if product.price %}
                                <p class="price"> {% if not product.special %}
                                    {{ product.price }}
                                    {% else %} <span class="price-new">{{ product.special }}</span> <span class="price-old">{{ product.price }}</span> {% endif %}
                                    {% if product.tax %} <span class="price-tax">{{ text_tax }} {{ product.tax }}</span> {% endif %} </p>
                                {% endif %}
                                {% if product.rating %}
                                <div class="rating"> {% for i in 1..5 %}
                                    {% if product.rating < i %} <span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span> {% else %} <span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span>{% endif %}
                                {% endfor %} </div>
                            {% endif %}
        
        <div class="button-group incep">
                            <button type="button" onclick="cart.add('{{ product.product_id }}', '{{ product.minimum }}');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md">{{ button_cart }}</span></button>
                        </div>
        
         {% endif %}
         
         {% for product in products %}.  
<script type="text/javascript">

    $('#button-cart_{{ product.product_id }}').on('click', function() {
        $.ajax({
            url: 'index.php?route=checkout/cart/add',
            type: 'post',
            data: $('#product-category #options_div_{{ product.product_id }} input[type=\'text\'], #product-category #options_div_{{ product.product_id }} input[type=\'hidden\'], #product-category #options_div_{{ product.product_id }} input[type=\'radio\']:checked, #product-category #options_div_{{ product.product_id }} input[type=\'checkbox\']:checked, #product-category #options_div_{{ product.product_id }} select, #product-category #options_div_{{ product.product_id }} textarea'),
            dataType: 'json',
            beforeSend: function() {
                $('#button-cart').button('loading');
            },
            complete: function() {
                $('#button-cart').button('reset');
            },
            success: function(json) {
                $('.alert-dismissible, .text-danger').remove();
                $('.form-group').removeClass('has-error');

                if (json['error']) {
                    if (json['error']['option']) {
                        for (i in json['error']['option']) {
                            var element = $('#input-option' + i.replace('_', '-'));

                            if (element.parent().hasClass('input-group')) {
                                element.parent().after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
                            } else {
                                element.after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
                            }
                        }
                    }

                    if (json['error']['recurring']) {
                        $('select[name=\'recurring_id\']').after('<div class="text-danger">' + json['error']['recurring'] + '</div>');
                    }

                    // Highlight any found errors
                    $('.text-danger').parent().addClass('has-error');
                }

                if (json['success']) {
                    $('.breadcrumb').after('<div class="alert alert-success alert-dismissible">' + json['success'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');

                    $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');

                    $('html, body').animate({ scrollTop: 0 }, 'slow');

                    $('#cart > ul').load('index.php?route=common/cart/info ul li');
                }
            },
            error: function(xhr, ajaxOptions, thrownError) {
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
        });
    });
</script> 
{% endfor %}
Last edited by ianhaney50 on Fri Dec 13, 2024 3:21 am, edited 1 time in total.

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by ADD Creative » Thu Dec 12, 2024 5:41 pm

Is there a $result['product_id'], or do you mean to use $product_id?

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by ianhaney50 » Thu Dec 12, 2024 5:44 pm

ADD Creative wrote:
Thu Dec 12, 2024 5:41 pm
Is there a $result['product_id'], or do you mean to use $product_id?
Sorry how do I find that out, do I need to use echo?

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by ianhaney50 » Thu Dec 12, 2024 6:29 pm

Sorry sorted it, In catalog/controller/extension/module/featured.php I changed the line below from

Code: Select all

'options'      => $this->model_catalog_product->getProductOptions($result['product_id']),
TO

Code: Select all

'options'      => $this->model_catalog_product->getProductOptions($product_info['product_id']),

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by OSWorX » Fri Dec 13, 2024 1:55 am

ianhaney50 wrote:
Thu Dec 12, 2024 6:29 pm
Sorry sorted it, ...
Means - you have found your solution?
If, then mark this topic as [SOLVED]

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by ianhaney50 » Fri Dec 13, 2024 3:20 am

Sorry yeah I solved it, I'll mark it solved now

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am
Who is online

Users browsing this forum: No registered users and 22 guests