• There are different options available for icon sets for cart icon at - commerce/icons/
  • There is no any configurations available to change them from default white icon set to another
  • Code for icon in use is written at - commerce/modules/cart/src/Plugin/Block/CartBlock.php LINE NO: 153
    '#uri' => drupal_get_path('module', 'commerce') . '/icons/ffffff/cart.png',
  • White color based icons will never displayed properly with the White Background

Comments

Ujval Shah created an issue. See original summary.

Ujval Shah’s picture

Title: Icons Paths are static - not configurable » Icon Paths are static - not configurable
willeaton’s picture

Status: Active » Closed (works as designed)

I believe this is done through theming. In your theme, open up the MYTHEME.theme file. Using twig debug mode you can identify the preprocess function you need to create, in this case:

commerce_cart_block

In there you can debug the variables provided, one of which is the icon. So lets say you want to change from #FFFFFF to #BEBEBE you would do the following:

function mytheme_preprocess_commerce_cart_block(&$variables) {
  $variables['icon']['#uri'] = drupal_get_path('module', 'commerce') . '/icons/bebebe/cart.png';
}

By the same means you can change any other aspect of the cart block here, even providing more info to the twig file, which you can also overwrite.

willeaton’s picture

Extension...
Using the SVG icons provided you can actually change the image to whatever colour you want. I think this would actually make sense to be the default icon. Here is my code snippet in case it helps anyone in the future

function mytheme_preprocess_commerce_cart_block(&$variables) {
  // Load SVG icon instead of image by default
  $svg = file_get_contents(drupal_get_path('module', 'commerce') . '/icons/ffffff/cart.svg');
  $variables['icon'] = [
    '#type' => 'inline_template',
    '#template' => $svg,
  ];
  // Add a library asset when the cart block is displayed so I can change the colour of the icon via css
  $variables['#attached']['library'][] = 'mytheme/cart-block';
}
mariogalan’s picture

Very useful, thanks @willeaton!

fahadurrehman’s picture

Thanks for such a useful snippet. Is there any way we can change the viewBox value ?

rwilson0429’s picture

Thanks @willeaton. Using the code snippet in #4, the icon css is inline, so, I had to use the css !important attribute in an external css file to override the inline style.

.cls-1 {
	fill: #393434 !important;
}
Annelies Van der Wee’s picture

Thank you all, works like a charm!

yurg’s picture

For those found this in 2024: drupal_get_path() is deprecated.
Now it is \Drupal::service('extension.list.module')->getPath('commerce')