Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. ## Dormify Swatch Breakdown
  2.  
  3. ### Product Tags
  4. Using product tags structured like `data-{key}:{value}`. This allows easy splitting and manipulation within liquid templates.
  5. ```
  6. "data--apt:APT"
  7. "data--color:Light Blue"
  8. "data--color:Purple"
  9. "data--sub-category:Decorative Pillows"
  10. ```
  11.  
  12. ### PLP Swatches
  13. The general structure for swatches on the PLP looks something like the following..
  14. ```html
  15. <div class="swatch-li tooltip swatch-active">
  16. <span class="tooltiptext">Natural</span>
  17. <div class="swatch hex-swatch"
  18. style="background-color: #ede6d6;"
  19. data-variant-color="Natural"
  20. data-variant-url="/products/cori-knit-pillow-rectangle?variant=39514077066"
  21. data-product-id="10328857418"
  22. data-variant-id="39514077066"
  23. data-variant-image="//cdn.shopify.com/s/files/1/1765/3959/products/dormify_thro_cora-knit-with-sequin-pillow-12x20-natural-gold_1_large.jpg?v=1489608384">
  24. <img src="//cdn.shopify.com/s/files/1/1765/3959/files/natural.png?15681987176840146952" class="swatch-image">
  25. </div>
  26. </div>
  27.  
  28. ```
  29. You can see each swatch on the PLP contains the following `data-` attributes.
  30. ```
  31. "data-variant-color"
  32. "data-variant-url"
  33. "data-variant-id"
  34. "data-variant-image"
  35. "data-product-id"
  36. ```
  37.  
  38. There is an onClick event that essentially does the following..
  39. ```
  40. onSwatchClick =>
  41. - Deactivate all swatches
  42. - Activate newly selected swatch
  43. - Update main image src
  44. - Update main image href with link to variant
  45. ```
  46.  
  47. #### Swatch Appearance
  48. All swatch colors are set using images with a background-color fallback. All swatch images are uploaded using the file uploader in the settings panel. They are all named specifically to match the colors used in the product variants (i.e. `purple.png`, `silver.png`).
  49.  
  50. I'm assuming they just get included in the liquid template in someway similar to this. If the image doesn't exist, nothing gets output and we see the swatch get styled via the background-color.
  51. ```liquid
  52. {% for color in all_colors %}
  53. <div class="swatch" style="background-color: {{ color }}">
  54. {{ color | append: '.png' | file_url | img_tag }}
  55. </div>
  56. {% endfor %}
  57. ```
  58.  
  59. ### PDP Swatches
  60. Don't work correctly. Clicking the swatch shows the associated variant image but that image isn't a thumb in the main gallery. Things get a little broken, the hover zoom image doesn't get updated.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement