Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallTo show the same product in two sizes as separate cart entries, make the selected size part of each cart line’s identity—or store it as a variant option and distinguish lines by their options. If your session cart is keyed only by product_id, adding another size will find the existing entry and increase its quantity instead.
Why the example merges different sizes
The SitePoint discussion’s example stores cart entries in $_SESSION['item_cart'], keyed by product ID. When an item is added, the code checks whether that ID is already present and increments the existing line’s quantity. Because size does not contribute to the lookup, a size 9 and a size 11 of the same product are treated as one line.
As an Amazon Associate I earn from qualifying purchases.
The question was raised in a SitePoint forum thread opened December 2, 2017. Participants suggested either combining product ID and size in the key, or storing size as an option. The thread does not include a completed implementation or verify the resulting cart output. Read the SitePoint discussion.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteChoose how cart lines represent variants
| Approach | How it distinguishes lines | When it fits | Trade-off |
|---|---|---|---|
| Composite key | Use a combination of product ID and size (or another unique combination) as the cart-line key. | A simple cart where one option, such as size, distinguishes the variants. | As more attributes are added, the key must represent their combination consistently. |
| Options stored on the line | Keep product identity and store selected attributes such as size, color, or fit as line options. | A cart that needs to represent different kinds or combinations of product attributes. | Cart lookup must compare the selected options as well as the product; matching product ID alone is not enough. |
These are design directions from the forum, not tested implementations. ZooKeeper, a forum participant, described options as more adaptable to products with attributes such as color and fit. Another participant, droopsnoot, suggested keying by product ID plus size or another unique combination. Neither comment establishes which approach is right for every store.
#1 Best Overall
What the cart should distinguish
A cart line represents a particular purchasable selection, not merely a catalog product. If two selections differ in an attribute that matters to the order—such as size—they need separate lines. If the same product and same selected options are added again, the cart can increment that matching line’s quantity.
- Same product, different size: keep separate lines.
- Same product, same size: combine into one line and increase its quantity, if that is the cart’s intended behavior.
- More attributes: compare the full selected combination, such as size and color, rather than only one attribute.
- Products without a size: represent the absence of that option consistently; the forum reply mentions a placeholder size, but does not prescribe a particular value or implementation.
Keep stock and variant identity in view
A forum participant also raised the possibility of using size-specific SKUs to represent variants and manage stock. That is a participant’s observation, not a requirement established by the thread. The important modeling question is whether each size or other option is separately sellable or stocked. If so, the cart’s line identity and the store’s variant or SKU model should identify that specific selection, rather than collapsing all sizes into one product-level quantity.
Rank #2
The 2017 discussion does not specify an inventory model, database schema, or tested PHP solution, so it cannot determine how a particular store should connect cart options to its stock records.
What the original thread does—and does not—answer
The thread identifies why the sample merges sizes and presents two ways to think about distinguishing them: composite keys and stored options. It does not supply the requested final output, a working code change, or test results. Treat it as a discussion of the data-modeling problem, not as a production-ready implementation.
Quick Recap
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




