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

Short description feature for products #177

Open
ltfschoen opened this issue Dec 15, 2020 · 3 comments
Open

Short description feature for products #177

ltfschoen opened this issue Dec 15, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@ltfschoen
Copy link
Contributor

ltfschoen commented Dec 15, 2020

On the product list page http://localhost:3000/collection, if the user provides a very long description for a product's description, it isn't pleasant to view the list of products. I think only a "short-description of a product" should be shown on that product list page, with a max length so it only takes up two lines of text.

So the metadata of a product could be:

  {
    "product": {
      "name": "Otani UltraDiamond",
      "short-description": "The most indulgent Microdermabrasion treatment you will ever experience"
      "long-description": "The most indulgent Microdermabrasion treatment you will ever experience. With all the benefits of microdermabrasion such as smoothing coarse textured skin and softening fine lines and wrinkles, scarring and hyper-pigmentation. This facial is set apart with the luxurious aromatherapy massage and Icy globes massage to soothe and calm the skin as well as minimise pore size. LED is used to regulate natural oil production whilst stimulating collagen and elastin and minimising redness and wrinkles. Finished with Rose Quartz GuaSha massage it cant be beat. (All skin types).",
      "price": "120.00"
...

If the user clicks one of the products on the product list page, it takes them to the product detail page (e.g. http://localhost:3000/product/oOZlSF), where the "long-description of a product" may be shown.

For example, here's a long description on the product list page, there isn't enough room to view the text, and certainly no room to have an image to show alongside the product

Screen Shot 2020-12-16 at 1 39 20 am

Whereas here's are either no description or a very short description on the product list page, which provides enough space to show the image of each product too

Screen Shot 2020-12-16 at 1 41 49 am

I guess the alternative is for the description that's shown on the product list page to be truncated to the desired length. What do you think?

@ltfschoen
Copy link
Contributor Author

Perhaps truncate the description to say 40 characters on that product list page so it appears like this instead:

Screen Shot 2020-12-16 at 2 15 19 am

Use a function to truncate it like:

  truncateDescription = (str, num) => {
    if (num > str.length){
      return str;
    } else {
      // Only keep the first 'num' characters
      str = str.substring(0, num);
      return str + "...";
    }
  }

And call it with:

description && this.truncateDescription(description, 40).replace(reg, '')

Where reg is defined as:

const reg = /(<([^>]+)>)/ig;

See the commit in my fork of how i implemented it ltfschoen/commercejs-nextjs-demo-store@24044e4

@robbieaverill
Copy link
Contributor

Thanks for raising this. You could also use CSS to provide the ellipsis rather than truncating in code. Pull requests welcome!

@robbieaverill robbieaverill added the enhancement New feature or request label Dec 15, 2020
@talmax1124
Copy link

@ltfschoen Can you help me display the products in localhost? I can't get anyone from slack to help me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants