Search by

delgraf / module-cart-item-image-fix

Delgraf

Restores the core data (product_id, ...) on Magento 2 cart item images replaced by third-party modules, e.g. MageWorx Advanced Product Options, fixing conflicts with modules such as Swissup ProLabels, and sizes MageWorx option images in the mini cart to the theme

Package info

github.com/Delgraf/Magento2-CartItemImageFix

Type:magento2-module

pkg:composer/delgraf/module-cart-item-image-fix

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.1.0 2026-11-22 21:18 UTC

This package is auto-updated.

Last update: 2026-11-22 21:21:05 UTC


README

Delgraf_CartItemImageFix restores the core data (product_id, class, ratio and the other keys set by Magento) on cart item images that a third-party module has replaced with a block of its own.

Its main use case is the conflict between MageWorx Advanced Product Options and Swissup ProLabels, which breaks the shopping cart page.

It also makes the MageWorx option images in the mini cart and in the checkout sidebar use the image size of your theme, instead of a fixed 75×75 px.

The problem

When a custom option of MageWorx Advanced Product Options uses the replace or overlay image mode, MageWorx swaps the product image on the cart page for the option image. To do that it creates a new image block that only contains the image URL, size and label. The product ID is missing, and the plugins that other modules add to Magento's ImageBuilder never run.

Swissup ProLabels adds its labels to every product image and uses the product ID to find them. With the MageWorx block it gets null instead, and the whole cart page fails with:

TypeError: Swissup\ProLabels\Helper\Catalog::toHtmlProductLabels(): Argument #1 ($memoizationKey)
must be of type string, null given, called in .../Plugin/Block/Product/Image.php on line 36

The error only appears in the cart, and only for products added with an option that has an image in replace or overlay mode.

Small option images in the mini cart

For the mini cart and the checkout sidebar ("Order Summary"), MageWorx generates the option images at a fixed size of 75×75 px. Magento and most themes size these thumbnails with the mini_cart_product_thumbnail image in the theme's etc/view.xml. When the theme uses a larger size, products with an option image look smaller than the other products in the mini cart, and blurry in the checkout sidebar, where the 75 px image is stretched to the theme's size.

Features

  • Fixes the cart page error for options in both replace and overlay image mode.
  • Keeps the option image chosen by MageWorx: only the data that is missing is added, nothing is overwritten.
  • Product labels from Swissup ProLabels appear on the option image in the cart, as they do on the standard product image.
  • Mini cart and checkout sidebar: MageWorx option images in replace and overlay mode are generated at the theme's mini_cart_product_thumbnail size, so they match the other products and stay sharp.
  • Generic: it completes any cart item image block without product data, whichever module created it, and does not depend on MageWorx or Swissup.
  • Does nothing for cart items whose image already has its product data, so standard products are not affected.
  • Works without MageWorx too: the mini cart part only applies when MageWorx Advanced Product Options is installed.
  • No patches to vendor/, no database tables and no configuration.

Requirements

  • Magento Open Source / Adobe Commerce 2.4.x or Mage-OS, PHP 8.2+
  • Written against MageWorx Advanced Product Options (mageworx/module-optionfeatures 2.35.4) and Swissup ProLabels (swissup/module-pro-labels 1.10.5) on Magento 2.4.9

Installation

Run all commands from the Magento root directory, as the user that owns the Magento files. Back up your code and database first, and try the module on a staging site before production.

Option 1: Composer (recommended)

  1. Put the store in maintenance mode (production stores only):

    bin/magento maintenance:enable
  2. Download the module:

    composer require delgraf/module-cart-item-image-fix
  3. Enable the module and update Magento:

    bin/magento module:enable Delgraf_CartItemImageFix
    bin/magento setup:upgrade
  4. In production mode, compile the code. The module has no frontend files, so static content does not need to be deployed again:

    bin/magento setup:di:compile
  5. Clear the cache and leave maintenance mode:

    bin/magento cache:flush
    bin/magento maintenance:disable

Option 2: Manual (app/code)

  1. Download the latest version as a ZIP from the Tags page and extract it.
  2. Copy its contents to app/code/Delgraf/CartItemImageFix/, so that registration.php is at app/code/Delgraf/CartItemImageFix/registration.php.
  3. Run steps 1 and 3 to 5 of the Composer installation.

Check the installation

  1. Check that the module is enabled:

    bin/magento module:status Delgraf_CartItemImageFix
  2. On the storefront, add to the cart a product with a custom option whose image is in replace mode, and one with an option in overlay mode.

  3. Open the cart page. It should load without errors and show the option images. If the products have ProLabels labels, these appear on the images too.

  4. Open the mini cart and the checkout page. The option images should have the same size as the images of the other products, and look sharp.

Update

Read the CHANGELOG before updating, and back up your code and database. The module follows Semantic Versioning: minor and patch versions (1.x) are backward compatible, while a new major version (2.0) may need changes on your side.

Installed with Composer

  1. Check the installed version and whether a newer one is available:

    composer show delgraf/module-cart-item-image-fix
    composer outdated delgraf/module-cart-item-image-fix
  2. Put the store in maintenance mode (production stores only):

    bin/magento maintenance:enable
  3. Update the package. This stays within the version range in your composer.json (for example ^1.0), so it never jumps to a new major version:

    composer update delgraf/module-cart-item-image-fix

    To move to a new major version, change the constraint on purpose, for example composer require delgraf/module-cart-item-image-fix:^2.0.

  4. Update Magento, recompile (production mode), then clear the cache and leave maintenance mode:

    bin/magento setup:upgrade
    bin/magento setup:di:compile
    bin/magento cache:flush
    bin/magento maintenance:disable

Installed manually (app/code)

  1. Download the new version as a ZIP from the Tags page and extract it.

  2. Put the store in maintenance mode (step 2 above).

  3. Delete the old files and copy in the new ones, so that no file from the old version is left behind:

    rm -rf app/code/Delgraf/CartItemImageFix
    mkdir -p app/code/Delgraf/CartItemImageFix
    cp -R /path/to/extracted/Magento2-CartItemImageFix-x.y.z/. app/code/Delgraf/CartItemImageFix/
  4. Run step 4 above.

After updating

  • Check the version: composer show delgraf/module-cart-item-image-fix, or the CHANGELOG.md in the module folder for a manual installation.
  • Test the cart as described in Check the installation.

When you update MageWorx Advanced Product Options or Swissup ProLabels, test the cart again. If MageWorx fixes the problem in its own code, this module simply stops doing anything (the image already has its product data) and can be removed.

Configuration

There is nothing to configure. The module works as soon as it is enabled.

How it works

Cart page

  • etc/frontend/di.xml adds an after plugin to Magento\Checkout\Block\Cart\Item\Renderer::getImage(), the method the cart page uses to get each item's image.
  • The plugin has sortOrder 5, lower than the MageWorx plugin (10). In Magento, an after plugin with a lower sortOrder runs once the around plugins with a higher sortOrder have completed, so it receives the final image block, after MageWorx has replaced it.
  • If that block has no product_id, the plugin builds the standard image of the same product with Magento's ImageBuilder. This also runs the ImageBuilder plugins of other modules: Swissup ProLabels, for example, prepares the product labels there.
  • It then copies to the block only the keys it does not already have. The option image URL, size and label stay as MageWorx set them.

The extra image is built only for cart items whose image is missing its product data, so the cost is limited to those items.

Mini cart and checkout sidebar

  • around plugins on Magento\Checkout\CustomerData\ItemPool::getItemData() (mini cart) and Magento\Checkout\Model\DefaultConfigProvider::getConfig() (checkout sidebar), with sortOrder 5, wrap the MageWorx plugins (10). While they run, Model\MiniCartImageContext holds the mini_cart_product_thumbnail size of the current theme.
  • A before plugin on MageWorx\OptionFeatures\Helper\Data::getOverlayImageUrl() and getImageUrl() changes a request for 75×75 px to the theme's size, only while that context is active. Images for the cart page and the product page are not touched.
  • In the mini cart, the item's image width and height are then set to the theme's size. In the checkout sidebar Magento already sets them.
  • MageWorx saves the generated images by size, so the first time each option combination is shown they are created again at the new size. The old 75 px files stay in pub/media/mageworx/optionfeatures/ and can be deleted.

If the theme has no mini_cart_product_thumbnail size, or it is 75×75 px, nothing changes. The plugin on the MageWorx class is ignored when MageWorx Advanced Product Options is not installed.

Troubleshooting

The error still appears

  • Check that the module is enabled (bin/magento module:status Delgraf_CartItemImageFix) and that generated/ was rebuilt with setup:di:compile in production mode.
  • Check that the stack trace still goes through Magento\Checkout\Block\Cart\Item\Renderer::getImage(). Images rendered by other blocks or templates are outside the scope of this module.
  • If another module replaces the cart image with an around plugin whose sortOrder is lower than 5, this module runs before it and cannot complete its block. Please open an issue with the module name and the full stack trace.

The option images in the mini cart are still small

  • Clear the cache and reload the mini cart data: the mini cart is stored in the browser, so sign out and in again, or add a product to the cart, to rebuild it. A private window also works.
  • Check the size your theme sets for mini_cart_product_thumbnail in its etc/view.xml (or the parent theme's). The module uses that size.
  • If MageWorx changes the 75×75 px size in a future version, this part of the module stops applying. Please open an issue.

Uninstall

The module stores no data and adds no database tables or configuration, so removing its code is all it takes. Keep in mind that, without it, the cart page error comes back if the conflict between the other modules has not been fixed in the meantime, and the mini cart option images go back to 75×75 px.

To turn it off for a while, disable the module (step 2) and skip removing the files.

Installed with Composer

  1. Put the store in maintenance mode (production stores only):

    bin/magento maintenance:enable
  2. Disable the module:

    bin/magento module:disable Delgraf_CartItemImageFix
  3. Remove the package:

    composer remove delgraf/module-cart-item-image-fix
  4. Update Magento, recompile (production mode), then clear the cache and leave maintenance mode:

    bin/magento setup:upgrade
    bin/magento setup:di:compile
    bin/magento cache:flush
    bin/magento maintenance:disable

Alternatively, bin/magento module:uninstall Delgraf_CartItemImageFix does steps 2 and 3 in one command, also for Composer installations only.

Installed manually (app/code)

  1. Run steps 1 and 2 above.

  2. Delete the module folder:

    rm -rf app/code/Delgraf/CartItemImageFix

    If app/code/Delgraf/ is now empty, you can delete it too.

  3. Run step 4 above.

License

OSL-3.0 (Open Software License 3.0)