Jump to content

Home Featured For Mobile Theme Ps 1.5.6.


Scully

Recommended Posts

I saw some post -also older ones- asking if and how it would be possible to have the homefeatured module also working on the older ps mobile themes without having to upgrade to a PS 1.6. version. And YES  - it is possible. I would like to share how it works. The following changes have been tested on a PS 1.5.6.3. installation. Here is a link to check how it could look at the end.

 

http://mit100wir.ch/wirshop/?mobile_theme_ok

 
Adapt the php code to allow for a differend handling of desktop and mobile view. Make a copy from your original file before you begin with changes.
 
Change File ../modules/homefeatured/homefeatured.php
 
1st Action: Add the hook for the mobile device. This enables homefeatured module also and only on the start page of the mobile theme. The bold line is inserted within the install function.
 
        if (!parent::install()
            || !$this->registerHook('displayHome')
            || !$this->registerHook('header')
            || !$this->registerHook('displayMobileIndex')
            || !$this->registerHook('addproduct')
            || !$this->registerHook('updateproduct')
            || !$this->registerHook('deleteproduct')
        )
 
 
2nd Action: Allow for a 2nd .tpl file to cache to mobile view. Since the page size and also css is different, you won't be able to handle this with one tpl only. Find every _clearCache('homefeatured.tpl'); and make a second line (bold) look like this:

 

        $this->_clearCache('homefeatured.tpl');
        $this->_clearCache('homefeatured_mobile.tpl','homefeatured_mobile');
 
Note that there is a second parameter after the tpl which is necessary as cache-id.
 
3rd Action: Copy/Past hookDisplayHome to a new function named hookdisplayMobileIndex. The $nb = 4 is a fixed value which determines how many items to show on the mobile device. You can change it to any value suitable for you. Also change the corresponding tpl to the ones for the mobile theme.
 
    public function hookdisplayMobileIndex($params)
    {
        if (!$this->isCached('homefeatured_mobile.tpl', $this->getCacheId('homefeatured_mobile')))
        {
            $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
            $nb = 4;
            $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position");

            $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_mobile.tpl', $this->getCacheId('homefeatured_mobile'));
    }

 

 

New File homefeatured_mobile.tpl

 

After all this you only need a second .tpl file called homefeatured_mobile.tpl. To make it easy I decided to copy the code from category-product-list.tpl so it displays products like it would under the category pages. This approach avoids the need for new css parameters. Copy this file to the ../module/homefeatured directory or to your ../themes/themename/modules/homefeatured directory. If you have the latter one existing, it takes precedence of the module directory.

 

 

{*
* mit100wir.ch - 18.12.2015
*}

<!-- MODULE Home Featured Products -->
{if isset($products)}
    {assign var="today" $smarty.now|date_format:"%d.%m.%Y"}
    <h2>{l s='Featured products' mod='homefeatured'} {$today}</h2>
    <ul data-role="listview" id="category-list" class="ui-listview ui-grid-a">
    {foreach from=$products item=product name=products}
        <li class="ui-block-{if $smarty.foreach.products.index % 2}b{else}a{/if} product-list-row">
            <a href="{$product.link|escape:'htmlall':'UTF-8'}" data-ajax="false">
                <div class="product_img_wrapper"><img class="ui-li-thumb" src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')|escape:'html'}" alt="{$product.legend|escape:'htmlall':'UTF-8'}" /></div>
                <h3 class="ui-li-heading">{$product.name|escape:'htmlall':'UTF-8'}</h3>
                {if (!$PS_CATALOG_MODE AND ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
                    <p class="ui-li-price">
                    {if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}
                        {if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}
                    {/if}
                    </p>
                    {assign var='info3_str' value=' '}
                    {assign var='info3_class' value='on_sale'}
                    
                    {if isset($product.on_sale) && $product.on_sale && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE}
                        {capture assign='info3_str'}{l s='On sale!' mod='homefeatured'}{/capture}
                        {assign var='info3_class' value='discount'}
                    {elseif isset($product.reduction) && $product.reduction && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE}
                        {capture assign='info3_str'}{l s='Reduced price!' mod='homefeatured'}{/capture}
                        {assign var='info3_class' value='discount'}
                    {elseif ($product.quantity < 0)} {capture assign='info3_str'}{l s='Bestseller' mod='homefeatured'}{/capture}
                        {assign var='info3_class' value='discount'}                        
                    {/if}

                    <p class="ui-li-price-info {$info3_class}"><span>{$info3_str}</span></p>
                    <p class="availability">
                    {if isset($product.available_for_order) && $product.available_for_order && !isset($restricted_country_mode)}
                        {if ($product.allow_oosp || $product.quantity > 0)}{l s='available' mod='homefeatured'}{elseif (isset($product.quantity_all_versions) && $product.quantity_all_versions > 0)}{l s='Product available with different options' mod='homefeatured'}{else}{l s='Out of stock' mod='homefeatured'}{/if}
                    {else}
                         
                    {/if}
                    </p>
                    
                    {if isset($product.online_only) && $product.online_only}
                        <p class="online_only">{l s='Online only!' mod='homefeatured'}</p>
                    {/if}
                {/if}
                {if isset($product.new) && $product.new == 1}<p class="new">{l s='New' mod='homefeatured'}</p>{/if}
            </a>
        </li>
    {/foreach}
    </ul><!-- #category-list -->
{/if}
<!-- /MODULE Home Featured Products -->

 

 

Go to backoffice and deinstall - install homefeatured and clear smarty cache

 

This is necessary because of the new hoook in the php wouln't activated until a new install of the module.

After all clear the smarty cache.

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...