Post by Roymj » Tue Sep 18, 2012 1:54 pm

Hi Guys,

I am using the featured module to list products to my homepage. But while the product option works fine in the product details page, it doesnt work well in the homepage(featured module). The option values for the last product is getting repeated to all the product listings. Also add to cart has some problem. Can anyone provide a proper solution to this?

Code is as follows :

Controller :

Code: Select all

    $this->data['products'] = array();

          $products = explode(',', $this->config->get('featured_product'));      

          if (empty($setting['limit'])) {
             $setting['limit'] = 5;
          }
          
          $products = array_slice($products, 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['image_width'], $setting['image_height']);
                } else {
                   $image = false;
                }

                if (($this->config->get('config_customer_price') && $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')));
                } 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')));
                } else {
                   $special = false;
                }
                
                if ($this->config->get('config_review_status')) {
                   $rating = $product_info['rating'];
                } else {
                   $rating = false;
                }
                $this->data['products'][] = array(
                   'product_id' => $product_info['product_id'],
                   'thumb'       => $image,
                   'name'        => $product_info['name'],
                   'price'       => $price,
                   'product_description'       => $product_info['product_description'],
                   'special'     => $special,
                   'rating'     => $rating,
                   'reviews'    => sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']),
                   'href'        => $this->url->link('product/product', 'product_id=' . $product_info['product_id']),
                );   
                
             
             $this->data['options'] = array();
             //print_r($this->model_catalog_product->getProductOptions($this->request->get['product_id']));
             //die("");
             $option=$this->model_catalog_product->getProductOptions($product_id);
             //foreach ($this->model_catalog_product->getProductOptions($product_id) as $option) //{
                
                   $option_value_data = array();
                   
                   foreach ($option['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')));
                         } else {
                            $price = false;
                         }
                         
                         $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),
                            'price'                   => $price,
                            'price_prefix'            => $option_value['price_prefix']
                         );
                      }
                   }
                   
                   $this->data['options'][] = array(
                      'product_option_id' => $option['product_option_id'],
                      'option_id'         => $option['option_id'],
                      'name'              => $option['name'],
                      'type'              => $option['type'],
                      'option_value'      => $option_value_data,
                      'required'          => $option['required']
                   );               
                
             //}
             
          }
          }
View :

Code: Select all

     
     <?php foreach ($products as $product) { ?>

    <a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" /></a>   

    <?php if ($options) {  ?>
          <div class="options" style="color: #457A33; float: left;line-height: 23px; margin-right: 20px; width:300px;">
           
            <?php foreach ($options as $option) { ?>
            <?php if ($option['type'] == 'select') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option" style="float:left; width:150px;">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <select name="option[<?php echo $option['product_option_id']; ?>]">
                <option value=""><?php echo $text_select; ?></option>
                <?php foreach ($option['option_value'] as $option_value) { ?>
                <option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
                <?php if ($option_value['price']) { ?>
                (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                <?php } ?>
                </option>
                <?php } ?>
              </select>
              <br />
               <a href="#">What's this</a>
            </div>
           
            <?php } ?>
     <?php } ?>


http://itzmeroymj.wordpress.com/


Newbie

Posts

Joined
Mon Apr 11, 2011 7:56 pm

Post by alexfwd » Wed Dec 12, 2012 12:10 am

I have the same issue, I assume there's no way to do it?

gifts for her - for guys that are pants at romance http://suchabloke.com


New member

Posts

Joined
Wed May 30, 2012 12:15 am


Post by dheerajvermawd » Sun May 08, 2016 7:20 pm

I also want the same thing, but getting failed again and again. Someone please give me a solution. My version is 2.1.0.1


Posts

Joined
Mon Jan 11, 2016 3:29 pm
Who is online

Users browsing this forum: Bing [Bot] and 83 guests