2016-12-13 3 views
0

Ich bin neu bei Opencart und ich versuche, den Mengenrabatt in den vorgestellten Produkten anzuzeigen - ohne Erfolg. Ich benutze Opencart 2.3. Grundsätzlich möchte ich erreichen, dass die Variablen quantity und price von der Controller-Datei featured.php an die View-Datei featured.tpl übergeben werden. HierOpencart 2.3 - zeigt Rabatt in vorgestellten Erweiterung

ist, was ich versucht habe:

1) In der Datei /catalog/controller/extension/module/featured.php nach dem $product_info = $this->model_catalog_product->getProduct($product_id); ich den folgenden Code hinzugefügt:

$discounts = $this->model_catalog_product->getProductDiscounts($product_id); 

$data['discounts'][] = array(); 

foreach ($discounts as $discount) { 
    $data['discounts'][] = array(
'quantity' => $discount['quantity'], 
'price' => $discount['price'] 
); 
} 

2) In der Datei /catalog/view/theme/default/template/extension/module/featured.tpl ich den folgenden Code hinzugefügt:

<?php foreach ($discounts as $discount) { ?> 
<span> 
<?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?> 
</span><br> 
<?php } ?> 

Jede Hilfe würde sehr geschätzt werden!

Ich habe verschiedene andere Codevarianten ausprobiert (z. B. die gelieferte Lösung here), aber keinen Erfolg.

Antwort

1

Go \ Sprache \ de-de \ Erweiterung \ module \ featured.php In folgenden Code zum Katalog:

$_['text_discount']   = ' or more '; 

Go \ Controller \ Erweiterung \ Modul zum Katalog \ featured.php folgenden Zeilen finden Code:

$data['heading_title'] = $this->language->get('heading_title'); 

Fügen Sie die folgenden Codezeilen:

$data['text_discount'] = $this->language->get('text_discount'); 

Suche folgenden Codezeilen:

foreach ($products as $product_id) { 
    $product_info = $this->model_catalog_product->getProduct($product_id); 

Fügen Sie die folgenden Codezeilen:

$discounts = $this->model_catalog_product->getProductDiscounts($product_id); 

      $product_info['discounts'] = array(); 

      foreach ($discounts as $discount) { 
       $product_info['discounts'][] = array(
        'quantity' => $discount['quantity'], 
        'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']) 
       ); 
      } 

folgenden Codezeilen finden:

$data['products'][] = array(
        'product_id' => $product_info['product_id'], 

Direkt darunter folgenden Codezeilen hinzu:

'discounts'=>$product_info['discounts'], 

Jetzt gehen \ Ansicht \ Thema \ YOUR_ACTIVE_THEME \ template \ Erweiterung \ module \ featured.tpl

Finden folgenden Codezeilen zum Katalog:

<div class="button-group"> 
      <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"> 

darüber hinzufügen oder wo auch immer Sie zeigen aber Notwendigkeit wollen um innerhalb der Produktpalette:

<?php if ($product['discounts']) { ?> 
     <ul> 
      <hr> 
      <?php foreach ($product['discounts'] as $discount) { ?> 
      <li><?php echo $discount['quantity']; ?><?php echo $text_discount; ?><?php echo $discount['price']; ?></li> 
      <?php } ?> 
     </ul> 
     <?php } ?> 

Sie können die ocmod bei Show Discounts at featured module Ocmod OpenCart 2.3.02

+0

Erstaunlich Download! Danke vielmals! Du hast mir eine Menge Arbeit erspart :) – naecone

Verwandte Themen