2016-04-02 9 views
0

Ich muss die Meldung "Keine Produkte" oder "Es gibt keine Produkte, die der Auswahl entsprechen" anzeigen, wenn in meinem Block nichts angezeigt wird.Wie wird die Meldung "Keine Produkte" angezeigt, wenn sich in meinem benutzerdefinierten Block keine Produkte befinden?

<?php   
$manufacturer = Mage::registry('current_product')->getMerchantName(); 

$productCollection = Mage::getModel('catalog/product')->getCollection() 
->addAttributeToSelect('*') 
->addAttributeToFilter('merchant_name',$manufacturer); 
$productCollection->getSelect()->order('RAND()'); 
$productCollection->getSelect()->limit(5); 

foreach ($productCollection as $_product) 
?> 

<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(228) ?>" width="228" height="228" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a> 

<div class="product-details"> 
<p class="product-name"><a href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></p> 

<?php 
$merchant_name = $_product->getAttributeText('merchant_name'); 
if ($merchant_name){?> 
<div>by <?php echo $merchant_name;?> </div> 
<?php } 

else if ($_product->getIsEbayaffiliate()) { ?> 
<div>by eBay</div> 
<?php } 

else { ?> 
<div>by Home Done</div> 
<?php } ?> 

Auch ich muss getPriceHtml zum obigen Code hinzufügen, um den Produktpreis zu zeigen.

ich versucht habe <?php echo $this->getPriceHtml($_item, true) ?>

Antwort

0

Dort gehen Sie: (Hinweis: Verwendung Tags geschlossen wie <?php if(): ?> zur besseren Lesbarkeit)

<?php if(is_array($productCollection) && count($productCollection)): ?> 
    <?php foreach ($productCollection as $_product): ?> 
     <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(228) ?>" width="228" height="228" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a> 
     <div class="product-details"> 
      <p class="product-name"><a href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></p> 
     <?php $merchant_name = $_product->getAttributeText('merchant_name'); ?> 
     <?php if ($merchant_name):?> 
      <div>by <?php echo $merchant_name;?> </div> 
     <?php elseif($_product->getIsEbayaffiliate()): ?> 
      <div>by eBay</div> 
     <?php else: ?> 
      <div>by Home Done</div> 
     <?php endif; ?> 
     </div> 
    <?php endforeach; ?> 
<?php else: ?> 
// here goes whatever you want to display if no products found in list 
<?php endif; ?> 
+0

Ich habe Ihren Code wie folgt hinzugefügt https://jsfiddle.net/ fhp3uvbu /, aber ich bekomme keine PRODUKTE Nachricht, auch wenn ich einige Produkte im Attribut "getMerchantName" habe – user6036056

+0

@ user6036056 Sie können Ihr PHP auf diesem jsfiddle nicht wirklich laufen lassen. es ist nicht entworfen, PHP so zu interpretieren. Am besten ist es, mit dem Debuggen zu beginnen. Setzen Sie 'echo 'functionName gestartet" 'oder' print_r (array()) 'wenn Object oder Array an jedem Anfang und Ende (vor der Rückkehr, Pause oder Ausnahme) einer aufgerufenen Funktion in Ihrem Skript. Überprüfe, wie tief die Fehlersuche dauern wird. Du solltest wissen, was das verursacht. – Braza

Verwandte Themen