Prestashop module hook to product pages - php

I am developing a module in prestashop. The module has been hooked into left column and right column and its working fine with that. Now I want to show the module output in product footer page. So for that can someone tell me how to hook my module to the product details page? Any help and suggestions will be really appreciable.
My code for leftColumn and rightColumn is like this
function hookLeftColumn()
{
$defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
global $cookie, $smarty;
$value=array();
$result="SELECT status,app_id from "._DB_PREFIX_."storeblocks";
$value=Db::getInstance()->ExecuteS($result);
$smarty->assign('array',$value);
$smarty->assign('default',$defaultLanguage);
return $this->display(__FILE__, 'stores.tpl');
}
function hookRightColumn()
{
return $this->hookLeftColumn();
}

For product page, there are several hooks available in PS.
You can use displayLeftColumnProduct hook, which hooks modules just below the image of the product. You can also use displayRightColumnProduct which is for the right side section.
Another set of hooks is displayProductTab and displayProductTabContent , which are used for the tabs on the product page.
If these hooks don't help you, simply, then there are several other ways you can get your results. You can hook your module to any of that hooks which is more suitable for your needs, and then using css position and lft , top etc to move that hook to the required place.
If that is not a choice, then you will need to create your own hook and then using that hook on the product page. Please read this for creating your own hook
http://www.programmingtunes.com/creating-new-prestashop-hook/
Also for a complete list of the hooks in PS, please read this article in PS docs
http://doc.prestashop.com/display/PS15/Hooks+in+PrestaShop+1.5
Let me know if you still need any other details.
Thank you

notice:this answer is about prestashop 1.5 and also you can use it for prestashop 1.6 too.
if your means about product details page is the more info tab as i show in bellow image i can help you
step1.you should instal two hook in install function in your module
public function install() {
return parent::install() &&
$this->registerHook('displayProductTab')&&
$this->registerHook('displayProductTabContent')
}
step2:you should use them and return the some html code
i want add a new tab i use.
notice:id is dynamic you change it but class is static should be use as the selected.
also href is linked to the content id(you see that in step 3)
public function hookDisplayProductTab($params) {
return '<li>
<a id="myid" class="selected"
href="#linked">mytab</a>
</li>'
}
step3:if want when you click on mytab this show the it's content you add an other function.
notice:the href="#linked" at previous function is linked to the id="linked".
public function hookDisplayProductTabContent($params){
return <div id="linked" class="rte">
<div class="product-overview-full">
my contents
</div>
</div>
}
advanced:write your html or smarty in your .tpl and return theme weth this code
return $this->display(__FILE__, 'mytpl.tpl') ;
best regards.

Related

WordPress Divi shortcode adding

WordPress Divi Theme shortcode adding problem
My Divi version is 3.20.1. I am trying to add my own custom shortcode in the website. However, when I add this shortcode, the elements displayed using this shortcode appear both in the "Edit page" area top section besides the main page.
add_shortcode( "Btx_Show_Testimonial_Main_Page", 'lantry_btx_fun_Main_Page_Show_Testimonial');
function lantry_btx_fun_Main_Page_Show_Testimonial(){
include_once LANTRY_BITECHX_SHORTCODE_DIR_PATH."views/Main_Page_testimonial_show.php";
}
My question is, how can I remove this from the "Edit page" section ??
I provided some screenshot.
Divi module Image Option Select
Show top of the post page
When I remove Divi this problem will be solved. But I need to use Divi.
You can check if a adminuser is logged in and if not execute your function hope this helps but now you have to always log out or use incognito mode to see if its there:
add_shortcode( "Btx_Show_Testimonial_Main_Page", 'lantry_btx_fun_Main_Page_Show_Testimonial');
function lantry_btx_fun_Main_Page_Show_Testimonial(){
if (current_user_can( 'update_core' )) {
return;
}
include_once LANTRY_BITECHX_SHORTCODE_DIR_PATH."views/Main_Page_testimonial_show.php";
}
I don't think the problem comes from DIVI but from your shortcode. Please attach the content of your file Main_Page_testimonial_show.php
The shortcode callback shouldn't produce an output but should return the result.
You can find this on documentation website here. Please pay attention to
Note that the function called by the shortcode should never produce an
output of any kind. Shortcode functions should return the text that is
to be used to replace the shortcode. Producing the output directly
will lead to unexpected results. This is similar to the way filter
functions should behave, in that they should not produce expected side
effects from the call since you cannot control when and where they are
called from.
Here, simply you can create the shortcode in the functions.php file and on your Page/Posts you can use the Text Module and add the [shortcode].

Adding Javascript code to specific pages using Prestashop Module

I'm developing a custom Prestashop Module. The requirement is simple: Add a predefined block of javascript code to specific sections of the shopping process. Those are:
Home page
Product page
Product added to cart
Purchase completed
The code will be specific to each page.
I already read the basics of module development, but I can't find documentation for this specific functionality.
I already have a working module that is installable and configurable from the back office admin. I'm assuming I need to extend the footer and check the page currently being served, but I have no idea how to do this.
It's more simple than it appears :), you have to check in which page you are, in your hookDisplayHeader method add some if:
public function hookDisplayHeader($params){
/* some code */
// check if we are in homepage
if($this->context->controller->php_self == 'index'){
$this->context->controller->addJS('path-to-index-js');
}
// check if we are in product page
if($this->context->controller->php_self == 'product'){
$this->context->controller->addJS('path-to-product-js');
}
// and so on for all other pages
/* ... */
/* some code */
}
Also there is a global variable in js
page_name
Every page in PrestaShop has a unique value of page_name smarty variable.
This variable's value can be fetched through the following code in any controller:
$this->context->smarty->tpl_vars['page_name']->value
You can add a hook (i.e. hookHeader) and then add a condition in that hook for every page where you want to add the script.

How to change contact from 7 spinning arrow location?

i have used Contact from 7 in my WordPress Theme, there are lot of options but i did not find any option to change the location of the (loading/ spinning arrow).
i want to display loading arrow on the Top of contact from.
This is pretty old but maybe somebody still needs an answer.
To override the ajax loader the right thing to do is to filter out the CF7 php function wpcf7_ajax_loader with a custom one.
Just place this function inside functions.php inside your theme and you should be good.
# Override ajax loader
add_filter('wpcf7_ajax_loader', 'custom_wpcf7_ajax_loader');
function custom_wpcf7_ajax_loader () {
return get_bloginfo('stylesheet_directory') . '/images/custom-ajax-loader.gif';
}

WP Jetpack publicize insert default text(s)

How can I place a default text (hashtag) in the Custom Message?
The textarea is (located in line 643) under jetpack/modules/publicize/ui.php
I tried to put the text in front of $title in various ways, like:
<?php echo "#myhashtag $title"; ?>
or
<?php echo '#myhashtag '.$title; ?>
but it just echoes the text, not the $title.
Any ideas will be greatly appreciated.
You can use the approach of this Wordpress plugin i made (Publicize With Hashtags), which does exactly that. It basically use and action trigger bound to the 'save_post' native event.
If you want to develop your own one you can have a look at my Source Code on the project's GitHub page or in this installation & usage guide I wrote about it.
You can add a filter, like so, to your theme's functions.php or a site-specific plugin:
add_filter( 'wpas_default_prefix', 'add_default_publicize_hashtag_prefix', 10, 4 );
function add_default_publicize_hashtag_prefix() {
$default_tags = '#yourhastaghere ';
return $default_tags;
}
This will add your default hashtag before your title without you needing to hack the WordPress core.
jetpack/modules/publicize/ui.php itself states in its comments:
/**
* Only user facing pieces of Publicize are found here.
*/
You added your hashtag in the textarea which allows admins to enter a custom message (click edit and it will slide down with your hashtag).
As #Yazmin mentioned, the best way to permanently edit the message is using a filter. The filters available are wpas_default_prefix, wpas_default_message, and wpas_default_suffix.
Personally, I had no success using these filters and I'm interested in a working solution to this issue myself.

Wordpress basic concept - how to extend/override/customize a plugin hook?

I am working on a wordpress site and would like to clarify a basic concept that is definitely very important, and this is how to customize/extend a wordpress hook (at least that's what I think I want to do!)
As the real world example, I am setting up a wp-ecommerce site. When a user adds an item to the cart, I would like to do one or two more things than the original function does. Looking through the source, I find:
/wp-content/plugins/wp-e-commerce/wpsc-includes/ajax.functions.php
with the function:
function wpsc_add_to_cart()
I know I could simply edit the code right here, but obviously that is the completely wrong way to go about it as when the plugin is updated, I will lose changes. What is the correct way to extend a function that is part of a plugin, or wordpress for that matter?
Endless thanks in advance.
You can use the wordpress action hooks to resolve the code loss while plugin upgrade.
You can remove the function which is in plugin file by using remove_action hook and do your own code by adding add_action in your function.php file. So that you can customize your plugin code from theme's function.php.
Here are the examples to explain.I hope it will help.
http://codex.wordpress.org/Plugin_API
http://themeshaper.com/2009/05/03/filters-wordpress-child-themes/
I use a little supressed notice function (it lives in my child themes function.php page), for plugins that get irritating eg: please setup twitter account to use , this kind of warning is not useful at certain stages and sometimes just do not care for it.
function supressed_notices_active(){
echo '<div class="error"><p>Supressed Notices are active</p></div>';
}
if(function_exists('the_plugin_custom_function_call')){
remove_action('the_plugin_custom_function_call' );
add_action('admin_notices','supressed_notices_active');
}else{
function test_message_from_me(){
echo '<h1>show</h1>';
}
add_action('admin_notices','test_message_from_me');
}
So I create the supressed notice function to at least create a warning, so i remember.
Check if the target function exists with the function_exists($target_function) hook
then remove this action from running with the remove_action($tag,$target_function) hook
then just add your custom function with the add_action($tag,$target_function) hook (do not need to have a separate function this could just be a closure)
then else if the function does not exist either still run a new action or leave this section, it can be useful for testing to just add anything so you atleast get some feed back.
What you could try... Copy the function within the plugin file,
paste it into your themes functions.php file,
ie:
function wpsc_add_to_cart() {
global $wpdb, $wpsc_cart;
// default values etc..etc..
// new code here?
}
the only thing with this is, if the plugin is updated and that funciton is renamed or removed, changed or something you could start to run into trouble...
could you not ask the plugin developer to possibly add your requirements to it,
possibly for a small fee? but if your using it as your main shopping cart, then chances are, that small investment could be a good thing.
Marty

Categories