Add attribute to cart items in Magento, show separate in cart

Add attribute to cart items in Magento, show separate in cart

August 22, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Add attribute to cart items in Magento, show separate in cart

Handling Customized Products in Magento Cart: A Comprehensive Guide

As an experienced Magento developer, I understand that managing customized products can be complex, especially when you want to store unique identifiers for each customization and display them separately in the cart. Let’s dive into a step-by-step approach to solve this issue.

Understanding Your Requirements

You have products with complex customizations, identified by unique IDs generated outside of Magento. The primary goals are:

  1. Store these IDs with the corresponding product in the cart.
  2. Display each customized product as a separate line item in the cart and invoice, even if the SKU is the same.

Suggested Approach: Customization as a Product Attribute

The best approach to handle this scenario is to treat each customization as an additional attribute of the product. Here’s how you can implement it:

1. Create a New Attribute for Customization ID

  • Go to Catalog → Attributes → Manage Attributes.
  • Click on ‘Add New Attribute’.
  • Choose “Text” as the input type and give it a name like “Customization_ID”.
  • Set the scope to “Global”.

2. Update Your Product Pop-up Logic

Since the customization happens outside Magento, you’ll need to update your PHP code that handles the pop-up functionality. Currently, when a customer submits their custom design, make sure to:

  • Generate or receive the unique ID for that specific design.
  • Save this ID as the value of the “Customization_ID” attribute for that product.

3. Modify the Cart and Checkout Process

To ensure each customized product is treated separately in the cart:

3.1 Add a Customization Observer

Create an observer to listen to the controller_action_predispatch_checkout_cart_add event. In this observer, you can check if a custom ID exists for the current product being added to the cart.

public function addCustomItemToCart(Observer $observer)
{
    $product = $observer->getEvent()->getQuoteItem()->getProduct();

    // Check if Customization_ID is set for this product
    $customId = $product->getData('customization_id');

    if ($customId) {
        // Create a new quote item with the same SKU but different custom ID
        $newItem = $observer->getEvent()->getQuote()->addItem(
            'simple',
            $product->getId(),
            1,
            false
        );

        $newItem->setName($product->getName() . " (Customization ID: {$customId})");
    }
}

3.2 Update the Cart to Avoid Merging

By default, Magento merges items with the same SKU into a single line item in the cart. To prevent this for customized products:

  • Override app/code/core/Mage/Checkout/Model/Cart.php.
  • In the mergeItems method, add an additional check for the custom ID attribute before merging.

4. Display Customization IDs

To display the customization IDs on the invoice or in the admin panel:

  • Update your template files to include the new attribute.
  • Create a new column in the order item grid (app/design/adminhtml/default/default/template/sales/order/view/tab/items.phtml).

Conclusion

By following this approach, you can successfully store and display unique customization IDs for each product in the Magento cart. The key is to treat each customized version as a distinct entity by adding a new attribute and modifying the cart logic.

Remember to thoroughly test your implementation to ensure it handles edge cases appropriately, such as when multiple customers customize the same base product with different IDs.

For more advanced customizations or if you encounter any issues during the development process, I recommend reaching out to our experienced Magento development team at Laravel Company. We specialize in complex eCommerce solutions and can provide expert guidance tailored to your specific needs.

Happy coding!

Checkout Catalog Orders Customers

Our network