Hi I am very new to magento and i want to add a variable that is the size variable that i know exist when you look in the minicart but for some reason I cant seem to find the variable anywhere in the magento wishlist file that is cart.phtml I tried var_dump the $item but it just make the page dont even load. I also tried just use getProduct->getattribute('size') but it I dont know why still didnt work. I am very new in magento so I hope someone could help me with this. This is the cart.phtml file for magento wishlist.

 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.

/** @var \Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Cart $block */

/** @var \Magento\Wishlist\Model\Item $item */
$item = $block->getItem();
$product = $item->getProduct();
/** @var \Magento\Wishlist\ViewModel\AllowedQuantity $viewModel */
$viewModel = $block->getData('allowedQuantityViewModel');
$allowedQty = $viewModel->setItem($item)->getMinMaxQty();

<?php foreach ($block->getChildNames() as $childName) : ?>
    <?= /* @noEscape */ $block->getLayout()->renderElement($childName, false) ?>
<?php endforeach;?>
<div class="box-tocart">
    <fieldset class="fieldset">
    <?php if ($item->canHaveQty() && $product->isVisibleInSiteVisibility()) : ?>
        <div class="field qty">
            <label class="label" for="qty[<?= $block->escapeHtmlAttr($item->getId()) ?>]"><span><?= $block->escapeHtml(__('Qty')) ?></span></label>
            <div class="control">
                <input type="number" data-role="qty" id="qty[<?= $block->escapeHtmlAttr($item->getId()) ?>]" class="input-text qty" data-validate="{'required-number':true,'validate-greater-than-zero':true, 'validate-item-quantity':{'minAllowed':<?= /* @noEscape */ $allowedQty['minAllowed'] ?>,'maxAllowed':<?= /* @noEscape */ $allowedQty['maxAllowed'] ?>}}"
               name="qty[<?= $block->escapeHtmlAttr($item->getId()) ?>]" value="<?= /* @noEscape */ $block->getAddToCartQty($item) * 1 ?>" <?= $product->isSaleable() ? '' : 'disabled="disabled"' ?>>
    <?php endif; ?>
    <?php if ($product->isSaleable()) : ?>
    <div class="product-item-actions">
        <div class="actions-primary">
            <button type="button" data-role="tocart" data-post='<?= /* @noEscape */ $block->getItemAddToCartParams($item) ?>' title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>" data-item-id="<?= $block->escapeHtmlAttr($item->getId()) ?>" class="action tocart action btn btn-primary primary">
                <span class="fa fa-shopping-cart"></span>
                <span class="text"><?= $block->escapeHtml(__('Add to Cart')) ?></span>
    <?php else : ?>
        <?php if ($product->getIsSalable()) : ?>
            <p class="available stock" title="<?= $block->escapeHtmlAttr(__('Availability')) ?>">
                <span><?= $block->escapeHtml(__('In stock')) ?></span>
        <?php else : ?>
            <p class="unavailable stock" title="<?= $block->escapeHtmlAttr(__('Availability')) ?>">
                <span><?= $block->escapeHtml(__('Out of stock')) ?></span>
        <?php endif; ?>
    <?php endif; ?>

1 Answer 1


Magento by default not loading all attributes on cart page in phtml file. but you can add your attributes via "catalog_attributes.xml", that's best practice to achieve this.

You have to add a etc/catalog_attributes.xml to your module and do the following:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd">
       <group name="quote_item">
           <attribute name="size" />

Happy Coding. Cheers !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.