X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   How to display color name when swatch is chosen (https://forum.x-cart.com/showthread.php?t=76717)

rct 12-21-2018 12:13 PM

How to display color name when swatch is chosen
 
1 Attachment(s)
I already owned the color swatch mod for xcart 5, however I have a question, how do I display color name when swatch is chosen so that it will show next to the "color" attribute? See attachment for sample

When it is in mobile, people cannot see the selected color from the "popover" .

Do I change the CSS file or the js script?

Any suggestions? Thanks

qualiteam 12-22-2018 11:16 AM

Re: How to display color name when swatch is chosen
 
You could use 'Custom JS', perfectly suits this task.

rct 01-02-2019 12:27 PM

Re: How to display color name when swatch is chosen
 
Quote:

Originally Posted by qualiteam
You could use 'Custom JS', perfectly suits this task.

Found a script which might work , however I am not very sure which variable to use. Please help!

I put this in the colorswatch/controller.js


jQuery(function(){
$(".color-swatches input[type=radio]:").change(function(){
jQuery('.active-color').text($(".color-swatches input[name^="attribute_values"]:checked").val());
})
})

the following in colorswatch/body.twig
<span class ="active-color"></label>

rct 01-02-2019 08:14 PM

Re: How to display color name when swatch is chosen
 
1 Attachment(s)
Or if there's any other solutions , basically user complains about not able to see the color option when using mobile. See the attached pic.

If we can use tooltips or if there's a way to enlarge the "caption box"? I cannot find anything from the css file and the xcart techsupport will not help without any payment.

Thanks.

qualiteam 01-05-2019 12:22 PM

Re: How to display color name when swatch is chosen
 
1 Attachment(s)
Ok, I've done the following (the better way than JS).


1. Added the following method to XLite/Module/QSL/ColorSwatches/View/Product/AttributeValue/Customer/Select.php


PHP Code:

protected function getSwatchName(\XLite\Model\AttributeValue\AttributeValueSelect $value)
    {
        return 
$this->getOptionTitle($value);
      } 

2. In template customer/modules/QSL/ColorSwatches/product/attribute_value/select/body.twig added the following line

Code:

<h6> {{ this.getSwatchName(v)|raw }} </h6>


just after this line


Code:

            </li>
        {% endfor %}



And I got the following (screenshot attached).
You can play with CSS a bit to make it look different, but the idea is here.

rct 01-07-2019 09:05 AM

Re: How to display color name when swatch is chosen
 
Thank you very much for your help. The <h6> tag should be right after

{{ this.getModifierTitle(v)|raw }}

qualiteam 01-09-2019 11:54 AM

Re: How to display color name when swatch is chosen
 
Quote:

Originally Posted by rct
Thank you very much for your help. The <h6> tag should be right after

{{ this.getModifierTitle(v)|raw }}


That's correct.
But please remember that you should apply any changes to PHP code as a module, otherwise it will be overwritten during the next update of the cart (or the module in this particular case).
What I posted is just an example.


All times are GMT -8. The time now is 09:13 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.