Design Meets Code

Design Meets Code

WordPress · PrestaShop

  • Startseite
  • WordPress
  • PHP / Datenbanken
  • Ubuntu
  • Prestashop
  • Grafik
  • Glossar

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

2. Februar 2014 Leave a Comment

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

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

Mit Shuffle Funktion

	<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

	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:

	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:

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');
}

Filed Under: Prestashop Tagged With: Prestashop 1.6, Zufällige Anordnung von Produkten

Prestashop: Produkt-Tags in der Produktbeschreibung anzeigen

29. Januar 2014 Leave a Comment

Um Tags auf der Produkteinzelansicht zu zeigen, öffne die Datei product.tpl und suche die Zeile

<div id="primary_block" class="clearfix">

Direkt dahinter füge dann folgenden Code ein

<ul class="producttags">
    {foreach from=Tag::getProductTags(Tools::getValue('id_product')) key=k item=v}
        {foreach from=$v item=value}
            <li><a href="{$link->getPageLink('search', true, NULL, "tag={$value|urlencode}")}">{$value|escape:html:'UTF-8'}</a></li>
        {/foreach}
    {/foreach}
</ul>

Um die Tags zu stylen, füge folgende CSS Deklarationen in die global.css ein

.producttags {
    list-style:none;
    position:relative;
    clear:both;
    display:block;
    padding-bottom:20px;
    margin-bottom:20px;
}
 
.producttags li, .producttags a{
    float:left;
    height:24px;
    line-height:24px;
    position:relative;
    font-size:11px;
    }
 
.producttags a{
    margin-left:20px;
    padding:0 10px 0 12px;
    background:#0089e0;
    color:#fff;
    text-decoration:none;
    -moz-border-radius-bottomright:4px;
    -webkit-border-bottom-right-radius:4px;
    border-bottom-right-radius:4px;
    -moz-border-radius-topright:4px;
    -webkit-border-top-right-radius:4px;   
    border-top-right-radius:4px;   
}
.producttags a:visited{
    color:#fff;
}
 
.producttags a:before{
    content:"";
    float:left;
    position:absolute;
    top:0;
    left:-12px;
    width:0;
    height:0;
    border-color:transparent #0089e0 transparent transparent;
    border-style:solid;
    border-width:12px 12px 12px 0;     
}
 
.producttags a:after{
    content:"";
    position:absolute;
    top:10px;
    left:0;
    float:left;
    width:4px;
    height:4px;
    -moz-border-radius:2px;
    -webkit-border-radius:2px;
    border-radius:2px;
    background:#fff;
    -moz-box-shadow:-1px -1px 2px #004977;
    -webkit-box-shadow:-1px -1px 2px #004977;
    box-shadow:-1px -1px 2px #004977;
}
 
.producttags a:hover{background:#555; text-decoration:none;}   
 
.producttags a:hover:before{border-color:transparent #555 transparent transparent;}

Nun erscheinen die Produkt-Tags gleich oberhalb der Produktbeschreibung. Sie können natürlich auch an einer anderen Stelle eingefügt werden.

tags

Quelle: mypresta.eu

Ist der Shop mehrsprachig angelegt, so filtert der folgende Code die Tags nach Sprache:

{if isset($product->tags) && $product->tags}
<ul class="producttags">

{assign var='id_lang' value=Language::getIdByIso($lang_iso)}
{assign var='productTags' value=$product->tags}
{foreach from=$productTags[$id_lang] item=productTag name=productTags}
<li>  <a href="{$base_dir}index.php?controller=search&tag={$productTag|escape:'url'}"><strong>{$productTag}</strong></a></li>{if !$smarty.foreach.productTags.last}, {/if}
{/foreach}
</ul>
{/if}

Quelle: prestashop.com

Filed Under: Prestashop Tagged With: Prestashop 1.5, Produkt-Tags

WordPress 3.8 – Spaltenanzahl im Backend

18. Dezember 2013 Leave a Comment

In WordPress 3.8 fehlt die Möglichkeit, die Anzahl der Spalten im Backend zu bestimmen. So kann es bei einer hohen Auflösung z.B. im Widgetbereich passieren, dass man zwei Spalten für die Widgets und zwei Spalten für die Sidebars hat. Ein Textwidget mit der Maus von ganz unten nach oben in einen Widgetbereich zu ziehen, kann sich dann als eine schwierige Übung gestalten. Abhilfe schafft diese Funktion in der functions.php

function wpse126301_dashboard_columns() {
    add_screen_option(
        'layout_columns',
        array(
            'max'     => 2,
            'default' => 1
        )
    );
}
add_action( 'admin_head-index.php', 'wpse126301_dashboard_columns' );

Quelle: Stackexchange

Filed Under: WordPress Tagged With: Backend

  • « Previous Page
  • 1
  • …
  • 34
  • 35
  • 36
  • 37
  • 38
  • …
  • 44
  • Next Page »
Anzeige

Themen

Apache BuddyPress Code Snippets Datenbank Email Enfold genesis Grid View htaccess imscp Indesign Katalogpreisregel Layout Builder LibreOffice Lieferschein List View Logout Mitgliederbereich MySQL PHP PHP Anfänger PHP Variablen Plugins Prestashop Prestashop 1.5 Prestashop 1.6 Prestashop 1.7 Prestashop 8 Prestashop Module Registrierung RSS Feed s2member Screencast Server Sicherheit ssl Startseite Strings Tipps Windows Windows 10 Windows 11 WooCommerce WooCommerce Sortierung WordPress
Anzeige

Letzte Kommentare

  • Martin bei CSS: Automatische Silbentrennung in einzelnen Wörtern verhindern
  • Martin bei CSS: Automatische Silbentrennung in einzelnen Wörtern verhindern
  • Klaus bei Woocommerce: Shop Seiten neu generieren
  • Thomas bei WordPress: Einzelne Kategorien aus dem RSS Feed ausschließen
  • Bernhard bei CSS: Automatische Silbentrennung in einzelnen Wörtern verhindern

Informationen

  • Kontakt
  • Datenschutzerklärung
  • Impressum
  • Cookie-Richtlinie (EU)
  • Kontakt
  • Datenschutzerklärung
  • Impressum
  • Cookie-Richtlinie (EU)
Anzeige