Mini-Cart menampilkan Gambar Produk Induk bukan Gambar Produk


8

Saya punya kode yang akan menampilkan produk dalam mini-cart menggunakan ajax, ketika seorang pelanggan mengklik Add to Cart. Masalahnya adalah bahwa itu tidak menampilkan gambar produk anak sampai saya melakukan penyegaran halaman itu, melainkan menampilkan Gambar Produk Induk. Saya telah masuk ke bagian belakang dan mengubah "Gambar Produk yang Dapat Dikonfigurasi" dan "Gambar Produk Kelompok" untuk menampilkan Gambar produk tetapi tampaknya kode di bawah mengabaikan pengaturan ini:

<?php
    $_item = $this->getItem();
    $isVisibleProduct = $_item->getProduct()->isVisibleInSiteVisibility();
    $canApplyMsrp = Mage::helper('catalog')->canApplyMsrp($_item->getProduct(), Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type::TYPE_BEFORE_ORDER_CONFIRM);
?>
<li class="item">
    <?php if ($this->hasProductUrl()): ?>
        <a href="<?php echo $this->getProductUrl()?>" title="<?php echo $this->htmlEscape($this->getProductName()) ?>" class="product-image"><img src="<?php echo $this->getProductThumbnail()->resize(50, 50)->setWatermarkSize('30x10'); ?>" width="50" height="50" alt="<?php echo $this->htmlEscape($this->getProductName()) ?>" /></a>
    <?php else: ?>
        <span class="product-image"><img src="<?php echo $this->getProductThumbnail()->resize(50, 50)->setWatermarkSize('30x10'); ?>" width="50" height="50" alt="<?php echo $this->htmlEscape($this->getProductName()) ?>" /></span>
    <?php endif; ?>
    <div class="product-details">
                <p class="product-name"><?php if ($this->hasProductUrl()): ?><a href="<?php echo $this->getProductUrl() ?>"><?php endif; ?><?php echo $this->htmlEscape($this->getProductName()) ?><?php if ($this->hasProductUrl()): ?></a><?php endif; ?></p>
        <strong><?php echo $this->getQty() ?></strong> x

    <?php if ($canApplyMsrp): ?>

        <span class="map-cart-sidebar-item"><?php echo $this->__('See price before order confirmation.'); ?></span>

    <?php else: ?>

    <?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
        <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
            <?php echo $this->__('Excl. Tax'); ?>:
        <?php endif; ?>
        <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')): ?>
            <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?>
        <?php else: ?>
            <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()) ?>
        <?php endif; ?>
        <?php if (Mage::helper('weee')->getApplied($_item)): ?>
            <br />
            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
                <small>
                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                    <span class="nobr"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount'],true,true); ?></span><br />
                <?php endforeach; ?>
                </small>
            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                    <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></small></span><br />
                <?php endforeach; ?>
            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
                <small>
                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                    <span class="nobr"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></span><br />
                <?php endforeach; ?>
                </small>
            <?php endif; ?>
            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br /> <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?></span>
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>



    <?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
        <?php $_incl = $this->helper('checkout')->getPriceInclTax($_item); ?>
        <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
            <br /><?php echo $this->__('Incl. Tax'); ?>:
        <?php endif; ?>
        <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')): ?>
            <?php echo $this->helper('checkout')->formatPrice($_incl+$_item->getWeeeTaxAppliedAmount()); ?>
        <?php else: ?>
            <?php echo $this->helper('checkout')->formatPrice($_incl-$_item->getWeeeTaxDisposition()) ?>
        <?php endif; ?>
        <?php if (Mage::helper('weee')->getApplied($_item)): ?>
            <br />
            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
                <small>
                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                    <span class="nobr"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount'],true,true); ?></span><br />
                <?php endforeach; ?>
                </small>
            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                    <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></small></span><br />
                <?php endforeach; ?>
            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
                <small>
                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                    <span class="nobr"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></span><br />
                <?php endforeach; ?>
                </small>
            <?php endif; ?>
            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                <span class="nobr"><?php echo Mage::helper('weee')->__('Total incl. tax'); ?>:<br /> <?php echo $this->helper('checkout')->formatPrice($_incl+$_item->getWeeeTaxAppliedAmount()); ?></span>
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>

    <?php endif; //Can apply MSRP ?>

        <?php if ($_options = $this->getOptionList()):?>
        <div class="truncated">
          <div class="truncated_full_value">
            <dl class="item-options">
                <?php foreach ($_options as $_option) : ?>
                <dt><?php echo $this->htmlEscape($_option['label']) ?></dt>
                <dd>
                    <?php if (is_array($_option['value'])): ?>
                    <?php echo nl2br(implode("\n", $_option['value'])) ?>
                    <?php else: ?>
                    <?php echo $_option['value'] ?>
                    <?php endif; ?>
                </dd>
                <?php endforeach; ?>
            </dl>
          </div>

        </div>
        <?php endif; ?>
        <a href="<?php 
            $params = $this->getRequest()->getParams();
            if($params['isAjax'] == 1){
                $refererUrl = Mage::registry('referrer_url');
                if (empty($refererUrl)) {
                    $refererUrl = Mage::getBaseUrl();
                }
                $deleteUrl = $this->getUrl(
                    'checkout/cart/delete',
                    array(
                        'id'=>$_item->getId(),
                        Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->helper('core/url')->getEncodedUrl($refererUrl)
                    )
                );
            }else{
                $deleteUrl = $this->getDeleteUrl();
            }
            echo $deleteUrl; 
        ?>" title="<?php echo $this->__('Remove This Item') ?>" onclick="return confirm('<?php echo $this->__('Are you sure you would like to remove this item from the shopping cart?') ?>');" class="btn-remove"><?php echo $this->__('Remove This Item') ?></a>
        <?php if ($isVisibleProduct): ?>
        <a href="<?php echo $this->getConfigureUrl() ?>" title="<?php echo $this->__('Edit item') ?>" class="btn-edit"><?php echo $this->__('Edit item')?></a>
        <?php endif ?>

    </div>
</li>

Gunakan callback ajax untuk me-refresh blok mini cart yang memicu setelah selesai menambahkan ke cart oleh panggilan ajax. <br /> Saya tahu ini bukan solusi yang tepat tetapi sampai saat itu kita dapat menggunakan cara ini.
Piyush

Saya memiliki masalah yang sama. Kode apa yang Anda ubah untuk benar-benar menyelesaikan ini?
Justin

Jawaban:


3

Blok ini Mage_Checkout_Block_Cart_Item_Renderermemiliki fungsi overrideProductThumbnailyang akan memperbarui thumbnail mana yang akan digunakan saat merender produk dalam keranjang.

Selama _toHtmlpenyaji produk yang dikelompokkan Mage_Checkout_Block_Cart_Item_Renderer_Groupedini disebut.

protected function _toHtml()
{
    $renderer = $this->getRenderedBlock()->getItemRenderer($this->getItem()->getRealProductType());
    $renderer->setItem($this->getItem());
    $renderer->overrideProductThumbnail($this->getProductThumbnail());
    $rendererHtml = $renderer->toHtml();
    $renderer->overrideProductThumbnail(null);
    return $rendererHtml;
}

Sepertinya saya bahwa Anda belum menambahkan renderer item yang benar untuk jenis produk ini. Lihat file tata letak xml app/design/frontend/base/default/layout/checkout.xmluntuk mengetahui bagaimana hal ini dapat dicapai.

<block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/sidebar.phtml" before="-">
    <action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/sidebar/default.phtml</template></action>
    <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/sidebar/default.phtml</template></action>
    <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/sidebar/default.phtml</template></action>
    <block type="core/text_list" name="cart_sidebar.extra_actions" as="extra_actions" translate="label" module="checkout">
        <label>Shopping Cart Sidebar Extra Actions</label>
    </block>
</block>

Ini benar-benar jawaban yang benar, karena berhasil untuk proyek saya menggunakan tema PolarCore dan tidak memuat thumbnail yang benar. TERIMA KASIH.
Joe

Jadi, bagaimana Anda menambahkan perender yang benar ke respons AJAX Anda?
Justin

2

Bagi saya masalahnya adalah

Mage_Catalog_Model_Product_Type_Configurable::getProductByAttributes

Saya perlu mengganti metode dan menambahkan 'thumbnail' ke pilih. Yaitu

$productCollection = $this->getUsedProductCollection($product)->addAttributeToSelect('name')->addAttributeToSelect('thumbnail');

EE 1.14.x


0

Menggunakan:

if($product->getTypeId() == 'configurable'){
    $child = $product->getTypeInstance(true)->getProductByAttributes($params['super_attribute'], $product);
    $product = $child;
}

Ini mengatur produk kepada anak.

Kemudian gunakan:

Mage::helper('catalog/image')->init($product, 'thumbnail');

untuk mendapatkan thumbnail minicart Anda ^ _ ^

Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.