Verifica se un prodotto ha un attributo impostato su Sì
-
12-12-2019 - |
Domanda
Ho un attributo chiamato Bogof.C'è un modo per visualizzare una foto solo per mostrare l'oggetto è un acquisto ottenere un oggetto gratuito.L'attributo è un sì / no.
Qualcuno mi ha dato questo codice in passato ma non funziona sul mio file Product_slider.phtml File
$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
}
}
.
presumo che sia a causa del
$quote = Mage::getSingleton('checkout/session')->getQuote();
.
Ma non so come cambiarlo per farlo funzionare.
Questo è il mio file .phtml che mostra i prodotti nel mio cursore.
$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>
.
Grazie
Soluzione
Ho scoperto come fare questo sarà un po 'armilato intorno a tutto ciò che dovevo fare era avvolgere questa affermazione intorno all'immagine del mio prodotto.
<?php if($_product->getData('bogof')==1){?>
<div class="bogof_image"></div>
<?php } ?>
.
e crea alcuni CSS per la classe "Bogof_image" per avere l'immagine di sfondo del mio simbolo.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange