Design · PHP · Server

Design · PHP · Server

WordPress · Drupal · PrestaShop

  • Startseite
  • PHP
  • WordPress
  • Ubuntu
  • Prestashop
  • Indesign
  • Grafik

Zufällige Produktanordnung beim Featured Product Slider (PrestaShop 6.1.11 / Megashop Theme)

27. Januar 2017 2 Kommentare

Um beim Megashop Theme eine zufällige Produktsortierung im Featured Product Slider zu erreichen, wird der Code um folgende Zeile ergänzt:

1
shuffle($categories[$item]['products']);

In tptnprodcarousel.php nach folgender Funktion suchen: public function hookDisplayHome($params)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public function hookDisplayHome($params)
{
$cid = (Configuration::get('TPTNCRSL_SELECTED'));
$menu_item = explode(',', $cid);
$id_lang = (int)$this->context->language->id;
$id_shop = (int)Shop::getContextShopID();
$tptnprod_total = Configuration::get('TPTNCRSL_TOTAL');
$tptnprod_sortby = (Configuration::get('TPTNCRSL_SORTBY') ? 'position' : 'name');
$tptnprod_sortway = (Configuration::get('TPTNCRSL_SORTWAY') ? 'DESC' : 'ASC');
$categories = array();
 
foreach ($menu_item as $item) {
if (!$item)
continue;
$id = $item;
 
$category = new Category((int)$id, $id_lang);
if (Validate::isLoadedObject($category)) {
$categories[$item]['id'] = $item;
$categories[$item]['name'] = $category->name;
$categories[$item]['products'] = $category->getProducts($id_lang, 1, $tptnprod_total, $tptnprod_sortby, $tptnprod_sortway);
                            shuffle($categories[$item]['products']);
 
}
}
 
$this->smarty->assign(array(
'categories' => $categories,
'homeSize' => Image::getSize(ImageType::getFormatedName('home'))
));
 
return $this->display(__FILE__, 'tptnprodcarousel.tpl', $this->getCacheId());
}

Die Stelle, die geändert wird, befindet sich ungefähr in der Mitte der Funktion

1
2
3
4
5
6
7
8
$category = new Category((int)$id, $id_lang);
if (Validate::isLoadedObject($category)) {
$categories[$item]['id'] = $item;
$categories[$item]['name'] = $category->name;
$categories[$item]['products'] = $category->getProducts($id_lang, 1, $tptnprod_total, $tptnprod_sortby, $tptnprod_sortway);
                            shuffle($categories[$item]['products']);
 
}

Kategorie: Prestashop Stichworte: MegaShop, Prestashop 1.6

Prestashop: Zufällige Anordnung von Produkten im Featured Products Module

2. Februar 2014 Kommentar verfassen

Um eine zufällige Anordnung von Produkten im Featured Module zu erreichen, kann man die shuffle() Funktion wie folgt in homefeatured.tpl vor den for each-Loop einbauen

Ursprünglicher Code

1
2
<ul style="height:{$ulHeight}px;">
{foreach from=$products item=product name=homeFeaturedProducts}

Mit Shuffle Funktion

1
2
3
<ul style="height:{$ulHeight}px;">
{capture}{$products|@shuffle}{/capture}
{foreach from=$products item=product name=homeFeaturedProducts}

Es wird also die Zeile {capture}{$products|@shuffle}{/capture} eingefügt.

Nun muss noch die Cache Funktion ausgeschaltet werden, damit nicht der Cache, sondern die zufällige Produktanordnung gezeigt wird. Dies geschieht in der Datei homefeatured.php

Hier die folgende Funktion suchen

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public function hookDisplayHome($params)
{
if (!$this->isCached('homefeatured.tpl', $this->getCacheId()))
{
$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
$nb = (int)Configuration::get('HOME_FEATURED_NBR');
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position");
shuffle($products);
$this->smarty->assign(array(
'products' => $products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
));
}
return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId());

Hier wird nun die Zeile if (!$this->isCached(‚homefeatured.tpl‘, $this->getCacheId())) mit zwei vorangestellten // auskommentiert. Ebenso die nachfolgende öffnende und schließende geschweifte Klammer. In der letzten Zeile wird das letzte Komma und der nachfolgende Parameter mit dem Cachehinweis entfernt , $this->getCacheId() so dass die Funktion dann wie folgt aussieht:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public function hookDisplayHome($params)
{
// if (!$this->isCached('homefeatured.tpl', $this->getCacheId()))
// {
$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
$nb = (int)Configuration::get('HOME_FEATURED_NBR');
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position");
shuffle($products);
$this->smarty->assign(array(
'products' => $products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
));
// }
return $this->display(__FILE__, 'homefeatured.tpl');

Die Shuffle Funktion kann auch in die Funktion displayHome eingebaut werden und muss dann nicht in die homefeatured.tpl eingefügt werden:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public function hookDisplayHome($params){
$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
$nb = (int)(Configuration::get('HOME_FEATURED_NBR'));
/*$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));*/
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10), 'date_add', 'DESC', false, true, true, $nb);
 
shuffle($products);
$this->smarty->assign(array(
'products' => $products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize('home_default'),
));
return $this->display(__FILE__, 'homefeatured.tpl');
}

Kategorie: Prestashop Stichworte: Prestashop 1.6, Zufällige Anordnung von Produkten

Themen

Adminbar Apache Attachment Count Automatische Updates Backend Boolean values Boolesche Werte BuddyPress Code Snippets Concatenation Operator Conditional Statement Datenbank Email Enfold Escape Zeichen Galerien genesis Grid View htaccess Layout Builder List View Logische Operatoren Loops Maskieren Media Manager Mitgliederbereich PHP PHP Kommentare PHP Anfänger PHP Arrays PHP Variablen Plugins Prestashop Prestashop 1.5 Prestashop 1.6 RSS Feed s2member Server ssl Strings Windows Windows 10 WooCommerce WooCommerce Sortierung WordPress

Informationen

  • Kontakt
  • Datenschutzerklärung
  • Impressum

Neue Beiträge

  • Windows 10: Suchergebnisse im Standardbrowser anzeigen lassen und Edge deaktivieren
  • WordPress: Username über Link herausfinden
  • BuddyPress: Mitgliederliste modifizieren

Letzte Kommentare

  • Bernhard bei CSS: Automatische Silbentrennung in einzelnen Wörtern verhindern
  • Bernhard bei CSS: Automatische Silbentrennung in einzelnen Wörtern verhindern
  • MC bei PHP: Boolesche Werte (Boolean Values)
  • eno bei Zufällige Produktanordnung beim Featured Product Slider (PrestaShop 6.1.11 / Megashop Theme)
  • Sausebear bei Zufällige Produktanordnung beim Featured Product Slider (PrestaShop 6.1.11 / Megashop Theme)
Diese Website benutzt Cookies. Wenn Sie die Website weiter nutzen, stimmen Sie der Verwendung von Cookies zu.EinverstandenErfahren Sie mehr