Pregunta

Tengo un atributo llamado BOGOF.¿Hay una manera de mostrar una foto solo para mostrar que el artículo es una compra y obtenga un artículo gratis?El atributo es un sí / no.

Alguien me ha dado este código en el pasado, pero no funciona en mi archivo product_slider.phtml

$quote = Mage::getSingleton('checkout/session')->getQuote();
        $cartItems = $quote->getAllVisibleItems();
        foreach ($cartItems as $item)
        {
            $productId = $item->getProductId();
            $product = Mage::getModel('catalog/product')->load($productId);
                   if($product->getData('attributecode')==1){
             //direct delivery possaible

                }
                }

Supongo que es debido a la

$quote = Mage::getSingleton('checkout/session')->getQuote();

Pero no sé cómo cambiarlo para que funcione.

Este es mi archivo .phtml que muestra los productos en mi control deslizante.

$cms_id = $this->helper('settings')->getCurrentCmsPage();
if ( !$cms_id ) {
    $pageLayout = $this->getLayout()->getBlock('root')->getTemplate();
    if ( strpos($pageLayout, '2columns') ) {
        $grid_class = 'two_columns_' . Mage::getStoreConfig('settings/catalog/grid_columns_2col');
    } else {
        $grid_class = 'one_column_' . Mage::getStoreConfig('settings/catalog/grid_columns_1col');
    }
} else {
    if ( $cms_id == 'home' ) {
        $grid_class = 'one_column_' . Mage::getStoreConfig('settings/catalog/grid_columns_1col');
    } else {
        $grid_class = 'two_columns_' . Mage::getStoreConfig('settings/catalog/grid_columns_2col');
    }
}

$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
$helper = $this->helper('settings/image');
$imgX = 252;
$imgY = $helper->calculateHeight($imgX);
$time = time() + mt_rand(0, 1000);
?>
<?php if($_productCollection->count()): ?>
<div class="product-slider-container">
    <div class="clearfix title-container">
        <h2><?php echo $this->__($this->getBlockTitle());?></h2>
        <a href="#" class="jcarousel-prev-horizontal" id="carousel_prev<?php echo $time; ?>"></a>
        <a href="#" class="jcarousel-next-horizontal" id="carousel_next<?php echo $time; ?>"></a>
    </div>
    <ul id="featured_<?php echo $time; ?>" class="products-grid jcarousel-skin-tango clearfix <?php echo $grid_class; ?>">
        <?php foreach ($_productCollection as $_product): ?>
        <li class="item">

            <div class="regular">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image">
                    <?php echo $this->helper('settings')->getLabel($_product);  ?>
                    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($imgX, $imgY) ?>" data-srcX2="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($imgX*2, $imgY*2) ?>" width="<?php echo $imgX; ?>" height="<?php echo $imgY; ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
                </a>
                <div class="product-info">
                    <div class="button-container">
                        <?php if($_product->isSaleable()): ?>
                        <?php if (Mage::getStoreConfig('settings/ajax/cart')) : ?>
                            <?php if ( !($_product->getTypeInstance(true)->hasRequiredOptions($_product) || $_product->isGrouped()) ) { ?>
                                <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart ajax-cart" data-url="<?php echo $this->getAddToCartUrl($_product); ?>" data-id="<?php echo $_product->getId(); ?>"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
                                <?php } else { ?>
                                <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart show-options" data-id="<?php echo $_product->getId(); ?>"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
                                <?php }  ?>
                            <?php else: ?>
                            <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
                            <?php endif; ?>
                        <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                        <?php endif; ?>
                    </div>
                    <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
                    <a class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a>
                    <?php echo $this->getPriceHtml($_product, true) ?>
                </div>
            </div>

Gracias

¿Fue útil?

Solución

Descubrido cómo hacerlo, habrá un poco de desempeño de todo lo que tenía que hacer era envolver este estado de la imagen de mi producto.

<?php if($_product->getData('bogof')==1){?>
                    <div class="bogof_image"></div>
                        <?php } ?>

y crea algunos CSS para la clase "BOGOF_IMAGE" para tener una imagen de fondo de mi símbolo.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top