Jump to content

Hook a module on homepage but datas from controller php file are not loaded


shookai

Recommended Posts

Thanks for your help!

 

First of all I have added the PHP file which was not loading in the override of the front controller :

include_once(_PS_MODULE_DIR_ .'advansedwishlist/controllers/front/mywishlist.php');

 

in public function install() of the module I have added 

            $this->registerHook('displayNav')  &&
            $this->registerHook('displayHome')  &&
            $this->registerHook('displayHomeTabContent');

 

and 

    
    
        public function hookdisplayHome()
        {
         
          $data_template = $this->wishlistBildShortContent();
            $this->context->smarty->assign($data_template);
         return $this->display(__FILE__, 'mywishlist.tpl');
        }    
              
    public function hookdisplayHomeTabContent($params)
    {
            
        
//         {$link->getModuleLink('advansedwishlist', 'mywishlist', array(), true)|addslashes}

            $data_template = $this->wishlistBildShortContent();
            $this->context->smarty->assign($data_template);
             console_LOG($data_template);
           return $this->display(__FILE__, 'mywishlist.tpl');

    }      
 

I was not sure what was the correct hook, so I added the module to the 2 hooks where modules on the homepage are displayed.

The module is showing but all datas from the front controller module are not processed and no datas are showing.

 

Thanks!

 

 

 

 

 

Screen Shot 2020-01-25 at 8.14.47 AM.png

Screen Shot 2020-01-25 at 9.45.45 AM.png

Link to comment
Share on other sites

The problem is in the below line.

$this->context->smarty->assign($data_template);

It should be like

$this->context->smarty->assign('data_template',$data_template);

Then you use the data_template variable in the mywishlist.tpl

First try the above solution. In case its still not working, share the mywishlist.tpl code as well.

 

Link to comment
Share on other sites

It did not work ;-/

("$this->context->smarty->assign($data_template); "   works for other hooks )

code of mywishlist.tpl:

 


<script>
   var baseDir = '{$base_dir|addslashes}';
   var static_token = '{$static_token|addslashes}';
   var isLogged = true;
   var advansedwishlist_controller_url = '{$advansedwishlist_controller_url nofilter}';
   var mywishlist_url= '{$mywishlist_url nofilter}';
   var url_cart = "{$link->getModuleLink('ps_shoppingcart', 'ajax', array(), true)|escape:'html':'UTF-8'}";
   {if $advansedwishlistis17 != 1}
       var ps_ws_version = 'advansedwishlistis16';
   {else}
       var ps_ws_version = 'advansedwishlistis17';
   {/if} 
   var single_mode = '{$single_mode}';
</script>
<script>
   function openFeed(evt, feedName) {
     var i, x, tablinks;
     x = document.getElementsByClassName("feed");
     for (i = 0; i < x.length; i++) {
       x.style.display = "none";
     }
     tablinks = document.getElementsByClassName("tablink");
     for (i = 0; i < x.length; i++) {
       tablinks.className = tablinks.className.replace("feed_active", "");
     }
     document.getElementById(feedName).style.display = "block";
     evt.currentTarget.firstElementChild.className += " feed_active";
   }
</script>

<div id="mywishlist" class="{if $advansedwishlistis17 == 1}mywishlist_17{else}mywishlist_16{/if}">    
   <div id="nav_feed">
      <a href="javascript:void(0)" onclick="openFeed(event, 'SavedFeed');">
         <div class="feed_active tablink">Saved Search</div>
      </a>
      <a href="javascript:void(0)" onclick="openFeed(event, 'FavouriteFeed');">
         <div class=" tablink">Favourite Item</div>
      </a>
      <a href="javascript:void(0)" onclick="openFeed(event, 'FavouriteSeller');">
         <div class=" tablink">Favourite Seller Item</div>
      </a>
      <a href="javascript:void(0)" onclick="openFeed(event, 'RecentlyViewed');">
         <div class=" tablink">Recently Viewed</div>
      </a>
   </div>
   <div id="SavedFeed" class="feed" style="display:block">
      <h2>Saved Search</h2>
      {$products_data_list|print_r}
      {if isset($products_data_list) && count($products_data_list)}
      {foreach $products_data_list as $product_page_data}
      <div class="row_feed_{$product_page_data['id_pp_feed_collecter']}">
         <div class="clearfix">
            <h3 class="pull-left feed_nmu_{$product_page_data['id_pp_feed_collecter']}">
               <span>{ucfirst($product_page_data['name'])}</span>
               <a class="displayFeedNamePopup" href="javascript:;" 
                  data-id="{$product_page_data['id_pp_feed_collecter']}"
                  data-name="{ucfirst($product_page_data['name'])}"
                  data-frequency="{$product_page_data['frequency']}"
                  data-toggle="modal" data-target="#updateFeedNameModal"><i class="fa fa-edit"></i></a>
            </h3>
            <a href="{$product_page_data['category_url']}" class="btn view_all pull-right" target="_blank">View all ({$product_page_data['products_count']})</a>
         </div>
         {if isset($product_page_data['products']) && $product_page_data['products']}
         <div class="products-list">
            <div class="col-md-12">
               <div class="row">
                  {include file="../../../../../themes/ayon/product-list.tpl" products=$product_page_data['products'] wscustomsix=true}
               </div>
            </div>
         </div>
         {/if}
      </div>
      {/foreach}
      {/if}
   </div>
   <div id="FavouriteFeed" class="feed" style="display:none">
      <h2>Favourite Item</h2>
      {if $id_customer|intval neq 0}
      {if $wishlists}
      <div id="block-history" class="block-center hidden">
         <table class="table table-bordered">
            <thead>
               <tr>
                  <th class="col-xs-2 col-md-2">{l s='Name' mod='advansedwishlist'}</th>
                  <th class="col-xs-1 col-md-1">{l s='Qty' mod='advansedwishlist'}</th>
                  <th class="col-xs-1 col-md-1">{l s='Viewed' mod='advansedwishlist'}</th>
                  <th class="col-xs-2 col-md-2">{l s='Created' mod='advansedwishlist'}</th>
                  {if !$single_mode}
                  <th class="col-xs-2 col-md-2">{l s='Direct Link' mod='advansedwishlist'}</th>
                  <th class="col-xs-2 col-md-2">{l s='Default' mod='advansedwishlist'}</th>
                  <th class="col-xs-2 col-md-2">{l s='Delete' mod='advansedwishlist'}</th>
                  {/if}
               </tr>
            </thead>
            <tbody>
               {section name=i loop=$wishlists}
               <tr id="wishlist_{$wishlists.id_wishlist|intval}">
                  <td class="col-xs-2 col-md-2">
                     <input type="hidden" value="{$wishlists.id_wishlist|intval}" id="pp_wishlist_id" />
                     <a id="get_wishlist_{$wishlists.id_wishlist|intval}" href="#" onclick="javascript:event.preventDefault();WishlistManage('ws-block-order-detail', '{$wishlists.id_wishlist|intval}');">
                     {$wishlists.name|truncate:30:'...'|escape:'htmlall':'UTF-8'}
                     </a>
                  </td>
                  <td class="col-xs-1 col-md-1">
                     {assign var=n value=0}
                     {foreach from=$nbProducts item=nb name=i}
                     {if $nb.id_wishlist eq $wishlists.id_wishlist}
                     {assign var=n value=$nb.nbProducts|intval}
                     {/if}
                     {/foreach}
                     {if $n}
                     {$n|intval}
                     {else}
                     0
                     {/if}
                  </td>
                  <td class="col-xs-1 col-md-1">{$wishlists.counter|intval}</td>
                  <td class="col-xs-2 col-md-2">{$wishlists.date_add|date_format:"%Y-%m-%d"|escape:'htmlall':'UTF-8'}</td>
                  {if !$single_mode}
                  <td class="col-xs-2 col-md-2">
                     <a href="#" onclick="javascript:event.preventDefault();WishlistManage('ws-block-order-detail', '{$wishlists.id_wishlist|intval}');">
                     {l s='View' mod='advansedwishlist'}
                     </a>
                  </td>
                  <td class="col-xs-2 col-md-2 wishlist_default">
                     {if isset($wishlists.default) && $wishlists.default == 1}
                     <p class="is_wish_list_default">
                        {if $wl_custom_font}
                        <span class="jms-heart-1"></span>
                        {else}
                        {if $advansedwishlistis17 == 1}
                        <i class="material-icons">assignment_turned_in</i>
                        {else}
                        <i class="icon icon-check-square"></i>
                        {/if}
                        {/if}
                     </p>
                     {else}
                     <a href="#" onclick="javascript:event.preventDefault();(WishlistDefault('wishlist_{$wishlists.id_wishlist|intval}', '{$wishlists.id_wishlist|intval}'));">
                     {if $wl_custom_font}
                     <span class="jms-compare-1"></span>
                     {else}
                     {if $advansedwishlistis17 == 1}
                     <i class="material-icons">check_box_outline_blank</i>
                     {else}
                     <i class="icon icon-square"></i>
                     {/if}
                     {/if}
                     </a>
                     {/if}
                  </td>
                  <td class="col-xs-2 col-md-2 wishlist_delete">
                     <a class="icon" href="#" onclick="javascript:event.preventDefault();return (WishlistDelete('wishlist_{$wishlists.id_wishlist|intval}', '{$wishlists.id_wishlist|intval}', '{l s='Do you really want to delete this wishlist ?' mod='advansedwishlist' js=1}'));">
                     {if $wl_custom_font}
                     <span class="jms-arrows-remove-1"></span>
                     {else}
                     {if $advansedwishlistis17 == 1}
                     <i class="material-icons">delete</i>
                     {else}
                     <i class="icon-remove"></i>
                     {/if}
                     {/if}
                     </a>
                  </td>
                  {/if}
               </tr>
               {/section}
            </tbody>
         </table>
      </div>
      <div id="ws-block-order-detail">&nbsp;</div>
      {else}
      {if $single_mode}
      {l s='No products in the list' mod='advansedwishlist'}
      {/if}
      {/if}
      {/if}
   </div>
   <div id="FavouriteSeller" class="feed" style="display:none">
      <h2>Favourite Seller Item</h2>
      {if isset($favourite_sellers_products) && $favourite_sellers_products}
      {foreach $favourite_sellers_products as $sellerData}
      <div class="seller_row_{$sellerData['id_seller']}">
         <div class="clearfix">
            <h3 class="pull-left}">
               <span>Favourite Seller: {$sellerData['seller_name']}</span>
               &nbsp;&nbsp;&nbsp;<a class="removeFavSeller" href="javascript:;" 
                  data-id="{$sellerData['id_seller']}"><i class="fa fa-trash-o"></i></a>
            </h3>
            <a href="{$sellerData['seller_shop']}" class="btn view_all pull-right" target="_blank">View all ({$sellerData['products_count']})</a>
         </div>
         {if isset($sellerData['products']) && $sellerData['products']}
         <div class="products-list">
            <div class="col-md-12">
               <div class="row">
                  {include file="../../../../../themes/ayon/product-list.tpl" products=$sellerData['products'] wscustomsix=true}
               </div>
            </div>
         </div>
         {/if}
      </div>
      {/foreach}
      {/if}
   </div>
   <div id="RecentlyViewed" class="feed" style="display:none">
      <h2>Recently Viewed</h2>
      {if isset($most_viewed_products) && $most_viewed_products}
      <div class="clearfix">
         <h3 class="pull-left}">
            <span>Most viewed</span>
         </h3>
         <a href="{$most_viewed_products['category_url']}" class="btn view_all pull-right" target="_blank">View all ({$most_viewed_products['products_count']})</a>
      </div>
      {if isset($most_viewed_products['products']) && $most_viewed_products['products']}
      <div class="products-list">
         <div class="col-md-12">
            <div class="row">
               {include file="../../../../../themes/ayon/product-list.tpl" products=$most_viewed_products['products'] wscustomsix=true}
            </div>
         </div>
      </div>
      {/if}
      {/if}
   </div>   
</div>
{*
<ul class="footer_links clearfix">
      <li>
         <a class="btn btn-default button button-small" href="{$link->getPageLink('my-account', true)|escape:'html':'UTF-8'}">
         <span>
         <i class="icon-chevron-left"></i>{l s='Back to Your Account' mod='advansedwishlist'}
         </span>
         </a>
      </li>
      <li>
         <a class="btn btn-default button button-small" href="{$base_dir|escape:'html':'UTF-8'}">
         <span>
         <i class="icon-chevron-left"></i>{l s='Home' mod='advansedwishlist'}
         </span>
         </a>
      </li>
   </ul>
*}

 

 

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...