Forums / Templates, Stylesheets, Page Layout / How to change product attribute image swatches to display side-by-side

How to change product attribute image swatches to display side-by-side

Views: 7,854

Results 1 to 6 of 6
29 Mar 2016, 4:05 PM
#1
fjolsvith avatar

fjolsvith

New Zenner

Join Date:
Mar 2016
Location:
Norcatur, Kansas, USA
Posts:
88
Plugin Contributions:
2

How to change product attribute image swatches to display side-by-side

Okay, I have my website up for selling sheds on, and I have an option for shingle color. Each of the option values has an image for the color of each shingle type.

Zencart was showing these image swatches in a vertical line, and I was really unhappy with it, and started researching how to change this. I found this thread here but it didn't seem to help. So, being a hobbyist programmer, I started searching and experimenting with the PHP files and finally found where I could change a line to remove "<br class="clearBoth>" from between the image swatches to display them side-by-side:

Attachment 16174

Where I finally found this change to make was in the "/includes/modules/attributes.php" file. Line 478 has the text:

$tmp_attributes_image .= '<br class="clearBoth">' . "\n";

Here is the section of code starting about line 470:

// collect attribute image if it exists and to be drawn in table below
                  if ($products_options_names->fields['products_options_images_style'] == '0' or ($products_options_names->fields['products_options_type'] == PRODUCTS_OPTIONS_TYPE_FILE or $products_options_names->fields['products_options_type'] == PRODUCTS_OPTIONS_TYPE_TEXT or $products_options_names->fields['products_options_type'] == '0') ) {
                    if ($products_options->fields['attributes_image'] != '') {
                      $tmp_attributes_image_row++;

                      //              if ($tmp_attributes_image_row > PRODUCTS_IMAGES_ATTRIBUTES_PER_ROW) {
                      if ($tmp_attributes_image_row > $products_options_names->fields['products_options_images_per_row']) {
                        $tmp_attributes_image .= '<br class="clearBoth">' . "\n";
                        $tmp_attributes_image_row = 1;
                      }

                      $tmp_attributes_image .= '<div class="attribImg">' . zen_image(DIR_WS_IMAGES . $products_options->fields['attributes_image']) . (PRODUCT_IMAGES_ATTRIBUTES_NAMES == '1' ? '<br />' . $products_options->fields['products_options_values_name'] : '') . '</div>' . "\n";
                    }
                  }

Change it like this:

// collect attribute image if it exists and to be drawn in table below
                  if ($products_options_names->fields['products_options_images_style'] == '0' or ($products_options_names->fields['products_options_type'] == PRODUCTS_OPTIONS_TYPE_FILE or $products_options_names->fields['products_options_type'] == PRODUCTS_OPTIONS_TYPE_TEXT or $products_options_names->fields['products_options_type'] == '0') ) {
                    if ($products_options->fields['attributes_image'] != '') {
                      $tmp_attributes_image_row++;

                      //              if ($tmp_attributes_image_row > PRODUCTS_IMAGES_ATTRIBUTES_PER_ROW) {
                      if ($tmp_attributes_image_row > $products_options_names->fields['products_options_images_per_row']) {
                        $tmp_attributes_image .=  "\n";
                        $tmp_attributes_image_row = 1;
                      }

                      $tmp_attributes_image .= '<div class="attribImg">' . zen_image(DIR_WS_IMAGES . $products_options->fields['attributes_image']) . (PRODUCT_IMAGES_ATTRIBUTES_NAMES == '1' ? '<br />' . $products_options->fields['products_options_values_name'] : '') . '</div>' . "\n";
                    }
                  }

Be sure to remove the "." before the "\n"; . If you forget that, the compiler won't run the page.

29 Mar 2016, 5:40 PM
#2
fjolsvith avatar

fjolsvith

New Zenner

Join Date:
Mar 2016
Location:
Norcatur, Kansas, USA
Posts:
88
Plugin Contributions:
2

Re: How to change product attribute image swatches to display side-by-side

Okay, now I feel a little sheepish. I found a setting under the Option Names Manager to change this.

In the Option Names Manager, click Edit for the option you want to modify. Down below is a setting called "Attribute Images per Row:". Change this to how many you want across and it does the same thing as my code edit.

1 Apr 2016, 5:02 PM
#3
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: How to change product attribute image swatches to display side-by-side

I found a setting under the Option Names Manager to change this.
Hopefully, you have used the override system and your edited file is in a folder named for your template
https://www.zen-cart.com/content.php?228-understanding-the-override-system
https://www.zen-cart.com/content.php?78-how-do-i-set-up-the-template-overrides

Either way, you need to restore the original code by deleting the override file or replacing the edited core file

Zen-Venom Get Bitten

2 Apr 2016, 12:25 AM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to change product attribute image swatches to display side-by-side

Hopefully through reading those links will also see that you can/should establish your template in it's own unique folder structure rather than using the classic folder template override path. There are some hobbyist programmer benefits to it besides always having a clean copy of the original file. For example if you wanted to figure out if your change caused something or it is always that way you can swap between your version and the classic to see the difference. :) but as identified, not everything can be overriden, some things are either modified directly or something called an observer can be used to modify specific aspects.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

4 Nov 2019, 7:22 PM
#5
margecc avatar

margecc

Zen Follower

Join Date:
Feb 2007
Location:
Ontario, Canada
Posts:
234
Plugin Contributions:
0

Re: How to change product attribute image swatches to display side-by-side

You may feel a little "Sheepish" but you just made my life easier because you posted what you did! I appreciate it!

Thanks, Colleen
www.af-company.com
To err is human, but to really foul things up requires a computer. Farmers' Almanac, 1978

4 Nov 2019, 8:27 PM
#6
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,857
Plugin Contributions:
18

Re: How to change product attribute image swatches to display side-by-side

Also, check out adding an image to each Value of the dropdown. When the selection is made in the dropdown, the image will change with the selection.

Select Vanilla Almond, Chocolate Fudge, and Sweet-n-Spicy at https://allpecans.com/index.php?main_page=product_info&cPath=32&products_id=133

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com