Jump to content

[Tips] mengurutkan produk di homefeatured (new produk first)


Recommended Posts

cuma mau share gan.. mungkin agan2 ada yg blm tau cara urutin produk di homefeatured. kebanyakan urutan produknya dari yg lama. ada tips supaya produk yg tampil dimulai dari yg terbaru, nah mudah2an script ini bisa membantu

edit prestashop/modules/homefaetured/homefeatured.php (bukan yg TPL ya..)

hapus isinya lalu replace semua scriptnya dengan yg ini :


<?php

class HomeFeatured extends Module
{
private $_html = '';
private $_postErrors = array();

function __construct()
{
$this->name = 'homefeatured';
$this->tab = 'Tools';
$this->version = '0.9';

parent::__construct(); // The parent construct is required for translations

$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('Featured Products on the homepage');
$this->description = $this->l('Displays Featured Products in the middle of your homepage');
}

function install()
{
if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) OR !parent::install() OR !$this->registerHook('home'))
return false;
return true;
}

public function getContent()
{
$output = ''.$this->displayName.'';
if (Tools::isSubmit('submitHomeFeatured'))
{
$nbr = intval(Tools::getValue('nbr'));
if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr))
$errors[] = $this->l('Invalid number of product');
else
Configuration::updateValue('HOME_FEATURED_NBR', $nbr);
if (isset($errors) AND sizeof($errors))
$output .= $this->displayError(implode('
', $errors));
else
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
return $output.$this->displayForm();
}

public function displayForm()
{
$output = '
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'

'.$this->l('In order to add products to your homepage, just add them to the "home" category.').'

'.$this->l('Number of product displayed').'

<input type="text" size="5" name="nbr" value="'.Tools::getValue('nbr', Configuration::get('HOME_FEATURED_NBR')).'" />

'.$this->l('The number of products displayed on homepage (default: 10)').'


<input type="submit" name="submitHomeFeatured" value="'.$this->l('Save').'" class="button" />

</form>';
return $output;
}

function hookHome($params)
{
global $smarty;
$category = new Category(1);
$nb = intval(Configuration::get('HOME_FEATURED_NBR'));
$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10), 'date_add', 'DESC');
$smarty->assign(array(
'allow_buy_when_out_of_stock' => Configuration::get('PS_ORDER_OUT_OF_STOCK', false),
'max_quantity_to_allow_display' => Configuration::get('PS_LAST_QTIES'),
'category' => $category,
'products' => $products,
'currency' => new Currency(intval($params['cart']->id_currency)),
'lang' => Language::getIsoById(intval($params['cookie']->id_lang)),
'productNumber' => sizeof($products)
));
return $this->display(__FILE__, 'homefeatured.tpl');
}

}



yg saya pake presta 1.3 gan, tapi kayanya berfungsi di semua versi..

Note: backup dulu file aslinya supaya ga beresiko..

Mudah2an bermanfaat...

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

Terima kasih, namun saya kira tidak perlu di ganti semua codenya, hapus / cukup comment out aja:

$products = $category->getProducts((int)($params['cookie']->id_lang), 1, ($nb ? $nb : 10));


lalu insert tepat dibawahnya

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10), 'date_add', 'DESC');



perhatikan 'date_add' dan 'DESC'
keduanya adalah kunci untuk mengurutkan ...

  • Like 2
Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...
  • 2 months later...

klo dirandom gimana yah,,,,soalnya gak smua produk yang terbaru saya masukan ke home featured,,,,

Untuk tampil di home featured, maka produk harus masuk ke kategori Home.

Pakai kode ini untuk menmpilkan random (PS 1.4)

 

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10), 'date_add', 'DESC', false, true, true);

Link to comment
Share on other sites

  • 3 weeks later...
  • 4 weeks later...

kalau mengurutkan sesuai produk terbaru, tetapi bukan dari category home gimana ya?

saya sudah mencoba, dengan utak-atik pada bagian

 

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ?

yang angka 1 tersebut sepertinya kategori, stuck disitu saya hehe.. :wacko:

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 2 weeks later...

kalau mengurutkan sesuai produk terbaru, tetapi bukan dari category home gimana ya?

saya sudah mencoba, dengan utak-atik pada bagian

 

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ?

yang angka 1 tersebut sepertinya kategori, stuck disitu saya hehe.. :wacko:

 

iy, gmn y klo mau mengurutkan produk paling baru, tp d dalam category... tolong d bantu donk para suhu...

Link to comment
Share on other sites

Untuk tampil di home featured, maka produk harus masuk ke kategori Home.

Pakai kode ini untuk menmpilkan random (PS 1.4)

 

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10), 'date_add', 'DESC', false, true, true);

ini ditaroh dimana suhu?mohon pencerahaannya

Link to comment
Share on other sites

  • 3 weeks later...
  • 4 weeks later...
  • 2 weeks later...

klo mau mengurutkan yang di dalam "kategori", bagaimana caranya, Suhu....?? mengurutkan sesuai dari barang yang paling "baru"

HELP !! para suhuu... :(

 

Kalo mau kategori tertentu, querynya harus dikustomisasi lagi. karena kategori kan bisa unik di masing2 website.

Link to comment
Share on other sites

  • 3 months later...

saya memakai prestashop 1.4.7 kok enggak ada

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10), 'date_add', 'DES

kemana harus saya cari?

di PS1.4.7.3 ada di file modules/homefeatured/homefeatured.php baris ke-99

 

ini ditaroh dimana suhu?mohon pencerahaannya

Silakan baca di posting #4

 

tanya dong om Zaid, yang random koq gak bisa di pake ya?

PS1.4 kan?

Edited by Zaid (see edit history)
Link to comment
Share on other sites

klo mau mengurutkan yang di dalam "kategori", bagaimana caranya, Suhu....?? mengurutkan sesuai dari barang yang paling "baru"

HELP !! para suhuu... :(

  1. Masuk ke Admin Product Preference ( Back Office > Preference > Product )
  2. Atur Default Order by menjadi 'product added date'

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...

Terima kasih, namun saya kira tidak perlu di ganti semua codenya, hapus / cukup comment out aja:

$products = $category->getProducts((int)($params['cookie']->id_lang), 1, ($nb ? $nb : 10));

lalu insert tepat dibawahnya

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10), 'date_add', 'DESC');

 

perhatikan 'date_add' dan 'DESC'

keduanya adalah kunci untuk mengurutkan ...

 

nah ini dia Gan yang saya cari2.... terima kasih ya atas informasinya.... sy sdh coba dan berhasil....

 

 

salam kenal ya....

 

http://www.suryalistrik.com

Link to comment
Share on other sites

  • 2 months later...

Terima kasih, namun saya kira tidak perlu di ganti semua codenya, hapus / cukup comment out aja:

$products = $category->getProducts((int)($params['cookie']->id_lang), 1, ($nb ? $nb : 10));

lalu insert tepat dibawahnya

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10), 'date_add', 'DESC');

 

perhatikan 'date_add' dan 'DESC'

keduanya adalah kunci untuk mengurutkan ...

 

makasih gan :)

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...
×
×
  • Create New...