Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product & Category Description to be Parsed by Smarty #3427

Closed
bhsmither opened this issue Nov 13, 2023 · 27 comments
Closed

Product & Category Description to be Parsed by Smarty #3427

bhsmither opened this issue Nov 13, 2023 · 27 comments
Assignees
Milestone

Comments

@bhsmither
Copy link
Contributor

Feature Request:

On the admin, Product, Add/Edit, Description tab, add a checkbox that will cause to send the content through Smarty prior to displaying on the storefront.

products.index.php:

   <div id="description" class="tab_content">
      <fieldset>
         <h3>{$LANG.common.description}</h3>
         <div>
            <label for="product_parse">{$LANG.catalogue.product_parse}</label><span><input type="hidden" name="product_parse" id="product_parse" class="toggle" value="{$PRODUCT.product_parse}"></span>
         </div>
         <textarea name="description" class="textbox fck">{if $PRODUCT.description}{htmlentities($PRODUCT.description, ENT_QUOTES, 'UTF-8', true)}{/if}</textarea>
         <br>
         <h3>{$LANG.common.description_short} {$LANG.common.optional}</h3>
         <textarea name="description_short" id="description_short" class="textbox fck">{if $PRODUCT.description_short}{htmlentities($PRODUCT.description_short, ENT_QUOTES, 'UTF-8', true)}{/if}</textarea>
      </fieldset>
   </div>

catalogue.class.php:

                $GLOBALS['language']->translateProduct($product);
                $product['description'] = ($product['product_parse']==1) ? $GLOBALS['smarty']->fetch('string:'.$product['description']) : $product['description'];

language.xml:

<group name="catalogue">
  <string name="product_parse" introduced="6.5.4"><![CDATA[Parse Smarty Tags in Description]]></string>

Database table CubeCart_inventory: add column 'product_parse', TINYINT:1 UNSIGNED NULL DEFAULT 0

@bhsmither bhsmither changed the title Product Descrioption to be Parsed by Smarty Product Description to be Parsed by Smarty Nov 13, 2023
@abrookbanks
Copy link
Member

abrookbanks commented Mar 13, 2024

{$smarty.now|date_format:"%D"}

corrupts to

<p>0--&gt;</p>

@bhsmither
Copy link
Contributor Author

I cannot reproduce your corruption.

@abrookbanks
Copy link
Member

Hmm. Does this work for you?

Screen.Recording.2024-03-13.at.16.46.54.mp4

@bhsmither
Copy link
Contributor Author

That does not happen for me.

@abrookbanks
Copy link
Member

Which browser? I wonder if it's my version of Chrome.

@bhsmither
Copy link
Contributor Author

Latest Firefox.

@abrookbanks
Copy link
Member

abrookbanks commented Mar 13, 2024

Hmm. Same fault in Safari. I'll try the demo store...

@bhsmither
Copy link
Contributor Author

Editing email templates should have the same problem, no?

@abrookbanks
Copy link
Member

It works on the demo store https://demo.cubecart.com/cc6

Something must be different in my development build....

@bhsmither
Copy link
Contributor Author

Might have to try the Store Settings, Copyright.

@abrookbanks
Copy link
Member

Changing the config file from;

config.extraPlugins = 'showprotected,emoji,textmatch,autocomplete,textwatcher';

to this fixes it. So one of the new plugins for emoji is breaking it.

config.extraPlugins = 'showprotected';

abrookbanks added a commit that referenced this issue Mar 14, 2024
abrookbanks added a commit that referenced this issue Mar 14, 2024
@abrookbanks
Copy link
Member

It works with one instance of ckeditor but not two. We have a description and short description.

@abrookbanks
Copy link
Member

This is a real headache

abrookbanks added a commit that referenced this issue Mar 14, 2024
@abrookbanks
Copy link
Member

I think there is a compatibility issue with the showprotected plug-in and the latest version of ckeditor. It works when there is one instance of CKE but not two. It's far to advanced for me to debug and the code is minified.

Maybe we can revisit this later.

@bhsmither
Copy link
Contributor Author

bhsmither commented Mar 14, 2024

It works with one instance of ckeditor but not two. We have a description and short description.

Did not the 'short_description' always have the showprotected effect? Honestly, I never checked because I never planned to parse the short description.

@abrookbanks
Copy link
Member

The main config loads showprotected into every instance of ckeditor. The fault lied when there are more than one on a page.

Maybe there is a work around..

Screen.Recording.2024-03-14.at.16.53.16.mp4

@bhsmither
Copy link
Contributor Author

Again, not able to replicate your observation.

@abrookbanks
Copy link
Member

abrookbanks commented Mar 14, 2024 via email

@bhsmither
Copy link
Contributor Author

CC653. I also played with the CC demo. I have no issues there.

A key difference I see is that CC654 is expected to be using CKEditor 4.22.1, where CC653 is using CKEditor 4.12.1.

Did you not find that the extraPlugins, other than showprotected, was causing problems?

I will fetch CKEditor 4.22.1 and play with it.

@bhsmither
Copy link
Contributor Author

bhsmither commented Mar 14, 2024

Using the largest pre-built package of CKEditor4.22.1, the observations mentions earlier are confirmed.

However, my first experiment is on the Store Settings, Copyright and Offline tabs.

Further experiments show that editing config.js as follows:

// config.protectedSource.push(/{\S*?.*?\S}/g);

does not corrupt the editor contents.

Restoring protectedSource but commenting extraPlugins (with only showprotected listed) returns the corruption.

So, this suggests that there is a fault with protectedSource or the REGEX argument, and no fault with showprotected.

@bhsmither
Copy link
Contributor Author

There are differences in the CKEditor core file htmldataprocessor.js, function protectSource(), comparing 4.12.1 vs. 4.22.1.

@bhsmither
Copy link
Contributor Author

Analysis so far suggests (actually, a guess) that every instance of the editor that gets spun up per page request reads and implements the settings in config.js. Which is to say, config.protectedSource.push happens that many times.

In htmldataprocessor.js, function protectSource(), these regexes are processed.

My wild guess is that, now in this version, is: replacing {word} with {cke_temp} then follows that braces are found again. If this is the case, I tried to de-dupe the array, and tried to pop off the last element. Neither tactic seemed to affect the array of regexes.

@bhsmither
Copy link
Contributor Author

The following is my fix. Test extensively!

In config.js:
Was:
config.protectedSource.push(/{\S*?.*?\S}/g);
Now:
config.protectedSource = [/{\S*?.*?\S}/g];

Not pushing it onto the array. Just making it that array.

@abrookbanks
Copy link
Member

That works and it works well! Are you an actual genius Brian? Seems very much like you are.

@abrookbanks
Copy link
Member

Screenshot 2024-03-15 at 09 37 57

abrookbanks added a commit that referenced this issue Mar 15, 2024
@abrookbanks abrookbanks added this to the 6.5.4 milestone Mar 15, 2024
@abrookbanks abrookbanks self-assigned this Mar 15, 2024
@abrookbanks abrookbanks changed the title Product Description to be Parsed by Smarty Product & Category Description to be Parsed by Smarty Mar 15, 2024
@bhsmither
Copy link
Contributor Author

Are you an actual genius Brian?

Yes. Yes, I am.

@abrookbanks
Copy link
Member

abrookbanks commented Mar 15, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants