Jump to content

Hacking New Products Module


StewartF

Recommended Posts

Morning

 

Just a quick question this morning about the New Products module

 

1. Is it possible to display it horizontally I want it to go beneath Nav or beneath Top Menu or slider.  So need it to be able to be tranplantable into those hooks

 

2. Is it possible to randomise new products showing like you can do for home page featured

 

Thanks

 

Stewart

Link to comment
Share on other sites

The first one is easy, just clone hookDisplayRightColumn (or left) and rename it to hookDisplayTop to support the new position.

 

As for the other is a bit more complicated. Depending on your ps version, have a look at Product::getNewProducts, around line 2101 of product.ph (classes). There is an order by

 

$sql->orderBy((isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way));

Link to comment
Share on other sites

To close simply copy/paste the same and rename it to hookDisplayTop  as I said ;)

As for the script try changing it to ORDER BY RAND()

 

Okay second bit is no problem. I can find and do that.

 

The first part is still confused to me (Sorry). 

 

Where am I copying hook from ?

Is this done in  phpadmin? Or in site files?

There is already a displayTop.  Am I creating complete new hook then? Won't I need to do some extra work in Controller and homepage template? I ask this as I have read this and not sure if relevant?

 

Apologies. I have some programming and design knowledge but not necessarily enough by looks of it

 

Stewat

Link to comment
Share on other sites

you have to alter module file, not database etc.

blocknewproducts.php located in module directory /modules/blocknewproducts/

 

Okay so I have this:

 

    public function install()

    {

        $success = (parent::install()

            && $this->registerHook('header')

            && $this->registerHook('addproduct')

            && $this->registerHook('updateproduct')

            && $this->registerHook('deleteproduct')

            && Configuration::updateValue('NEW_PRODUCTS_NBR', 5)

            && $this->registerHook('displayHomeTab')

            && $this->registerHook('displayHomeTabContent')

        );

 

Do I just add:

 

&& $this->registerHook('displayTop') onto the bottom then?

 

Because you also have :

 

if ($success)

        {

            // Hook the module either on the left or right column

            $theme = new Theme(Context::getContext()->shop->id_theme);

            if ((!$theme->default_left_column || !$this->registerHook('leftColumn'))

                && (!$theme->default_right_column || !$this->registerHook('rightColumn')))

            {

                // If there are no colums implemented by the template, throw an error and uninstall the module

                $this->_errors[] = $this->l('This module need to be hooked in a column and your theme does not implement one');

                parent::uninstall();

                return false;

            }

        }

        

Which looks like more conditional positional instructions.  Does this need amending too?

 

Stewart

Link to comment
Share on other sites

Add the registerhook, then find hookDisplayHomeTabContent, copy the whole method, and change the name to hookDIsplayTop, then where it returns the tpl at the end, change the tpl name to another and create that file. THis way you can have 2 separate templates

Link to comment
Share on other sites

Add the registerhook, then find hookDisplayHomeTabContent, copy the whole method, and change the name to hookDIsplayTop, then where it returns the tpl at the end, change the tpl name to another and create that file. THis way you can have 2 separate templates

 

Okay  so this is here I'm at thanks to your patience guys:

 

blocknewproducts.php:

 

1st change

 

public function install()

    {

        $success = (parent::install()

            && $this->registerHook('header')

            && $this->registerHook('addproduct')

            && $this->registerHook('updateproduct')

            && $this->registerHook('deleteproduct')

            && Configuration::updateValue('NEW_PRODUCTS_NBR', 5)

            && $this->registerHook('displayHomeTab')

            && $this->registerHook('displayHomeTabContent')

            && $this->registerHook('displayTop')

        );

 

2nd change further down:

 

public function hookdisplayTop($params)

    {

        if (!$this->isCached('blocknewproducts_top.tpl', $this->getCacheId('blocknewproducts-home')))

        {

            $this->smarty->assign(array(

                'new_products' => BlockNewProducts::$cache_new_products,

                'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),

                'homeSize' => Image::getSize(ImageType::getFormatedName('home'))

            ));

        }

 

        if (BlockNewProducts::$cache_new_products === false)

            return false;

 

        return $this->display(__FILE__, 'blocknewproducts_top.tpl', $this->getCacheId('blocknewproducts-home'));

    }

 

And copying blocknewproducts.tpl copying it and renaming blocknewproducts_top.tpl

 

Problem is though that nothing appears and stuff is in odd places - see screenshot attached

post-738133-0-91152800-1413985180_thumb.jpg

Link to comment
Share on other sites

Right an improvement. Duplicate hook should be:

 

public function hookdisplayTop($params)
    {
        if (!$this->isCached('blocknewproducts_top.tpl', $this->getCacheId('blocknewproducts')))
        {
            $this->smarty->assign(array(
                'new_products' => BlockNewProducts::$cache_new_products,
                'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
                'homeSize' => Image::getSize(ImageType::getFormatedName('home'))
            ));
        }

        if (BlockNewProducts::$cache_new_products === false)
            return false;

        return $this->display(__FILE__, 'blocknewproducts_top.tpl', $this->getCacheId('blocknewproducts'));

 

But as I thought every thing is vertically in a tower rather than horizontally with descriptions etc underneath the images.

 

Stew

Link to comment
Share on other sites

Remove all cache references for now

 

 

public function hookdisplayTop($params)
    {

            $this->smarty->assign(array(
                'new_products' => $this->getNewProducts(),
                'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
                'homeSize' => Image::getSize(ImageType::getFormatedName('home'))
            ));


        return $this->display(__FILE__, 'blocknewproducts_top.tpl');

Link to comment
Share on other sites

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