Jump to content

Add links to configurable items on order form


Logman

Recommended Posts

Is it possible to add a link to a config item option on an order form? We have a service with lots of config upgrades and would like to add links to info pages so clients can understand what the upgrade options are if they haven't seen them already.

Thanks.

Link to comment
Share on other sites

1 hour ago, Logman said:

Is it possible to add a link to a config item option on an order form?

not from the settings.

whilst you could add the link code in the configurable option name, and then tweak the template to output it as a link, a button or whatever...

UKiTpVT.png

tcPfBqn.pnggOCLqX4.png

the problem is that code within the config option name will then be visible in the remaining cart stages... now it's simple enough to remove, but you'd end up editing multiple templates (ordersummary, viewcart and probably the invoice templates too).

i'd be tempted to just edit the configureproducts.tpl and add your code directly there... so if it were a one-off...

{if $configoption.id eq '16'}<a href="http://www.google.com" class="btn btn-success btn-xs" role="button">More Info</a>{/if}

Juby7Kn.png

if it's for multiple configurable options with different links, then you could use multiple if/else statements, or create an array of configurable option IDs and their relevant links - either in the template using Smarty, or using a ClientAreaPageCart hook...

Link to comment
Share on other sites

  • 4 weeks later...

I tried added the link html in the Option field but it just displayed code:

af8634f4ce81a978abd3125acde37789.png.ffbeefcab5caed8ffb25aa368c19a06c.png

I looked in the db and found the ID but I can't figure out where in configureproduct.tpl to place this code:

{if $configoption.id eq '644'}<a href="http://www.google.com" class="btn btn-success btn-xs" role="button">More Info</a>{/if}

Link to comment
Share on other sites

while Brian method could perfectly work, another option is to use ActionHooks for this task, simply create new PHP file inside /includes/hooks/ directory and place the following code inside it and it will do the job as intended to

<?php
/**
 * Allow links <a> in products configurable options name
 * @author SENTQ
 */

add_hook("ClientAreaPageCart", 1, function($vars){
    
    foreach ($vars['configurableoptions'] as $index => $option){
        
        $vars['configurableoptions'][$index]['optionname'] = html_entity_decode($option['optionname']);
        
    }
    
    return array("configurableoptions" => $vars['configurableoptions']);
    
});

 

Link to comment
Share on other sites

this improvement will do the same in view cart page

<?php
/**
 * Allow links <a> in products configurable options name
 * @author SENTQ
 */
// Shopping Cart
add_hook("ClientAreaPageCart", 1, function($vars){
    
    // Cart -> View
    if ($vars['action'] === "view"){
        foreach ($vars['products'] as $index => $product){
            foreach ($product['configoptions'] as $optionid => $option){
                $vars['products'][ $index ]['configoptions'][ $optionid ]['name'] = html_entity_decode($option['name']);
            }
        }
        
        return array("products" => $vars['products']);
    }
    
    // Cart -> Product Configuration
    if ($vars['action'] === "confproduct"){
        foreach ($vars['configurableoptions'] as $index => $option){
            
            $vars['configurableoptions'][ $index ]['optionname'] = html_entity_decode($option['optionname']);
            
        }
        
        return array("configurableoptions" => $vars['configurableoptions']);
    }
    
});

// Client Area -> Product Details Page
add_hook("ClientAreaPageProductDetails", 1, function($vars){
    
    foreach ($vars['configurableoptions'] as $index => $option){
        
        $vars['configurableoptions'][ $index ]['optionname'] = html_entity_decode($option['optionname']);
        
    }
    
    return array("configurableoptions" => $vars['configurableoptions']);
    
});

// Admin Area -> Product Details Page
add_hook("AdminAreaHeadOutput", 1, function($vars){
    
    if ($vars['filename'] != "clientsservices"){
        return;
    }
    
    return <<<EOF
<script type="text/javascript">
$(document).ready(function(){
    $(".fieldlabel").each(function(i, val){
        var final = $('<textarea />').html($(this).text()).text();
        $(this).html(final);
    });
});
</script>
EOF;
    
});

 

Edited by sentq
improvements
Link to comment
Share on other sites

in this case we need to use @brian! method, open the following file for editing:

/templates/orderforms/ordersummary.tpl

replace this line (#12):

<span class="pull-left">&nbsp;&raquo; {$configoption.name}: {$configoption.optionname}</span>

with this one:

<span class="pull-left">&nbsp;&raquo; {$configoption.name|unescape}: {$configoption.optionname}</span>

 

Link to comment
Share on other sites

I also figured out where to add unescape in the viewinvoice and clientareaproductdetails templates. Just need to work out the emails and also if possible the WHMCS admin client Products/Services page. I looked in the blend templates and see no mention of it. Can that be edited?

Link to comment
Share on other sites

The Hook works perfect, thanks.

Added the Smarty security policy for unescape, found I could simply add |unescape to $order_details, $order_items, $data_option etc.

Turned out to be a bit more involved than I though but worth it I think for upsells. Will the default Email Templates get written over on upgrades? Thanks so much for your help!

Link to comment
Share on other sites

FWIW, and this is probably too late for @Logman as he's likely too far down the road of removing from additional pages, but i'd be tempted to tweak @sentq hook code and instead of having the description/link in the option name, remove it from there and create a Language Override for that configurable option description and/or link..

there would be a number of advantages to this method...

  1. you can create your descriptions in multiple languages and the client will see the description in their chosen language (not necessarily English).
  2. the language overrides can contain HTML and/or css styling... including links specific to that language - e.g., French visitors might see one link, German users might see another.
  3. as you are now adding to the output only on specific pages, you no longer need to remove additional code from other templates such as ordersummary, invoices, emails etc.
  4. if a configurable option doesn't contain a language override description, then the hook will not attempt to add any code.
<?php
/**
 * Allow links <a> in products configurable options name
 * @author SENTQ
 */
// Shopping Cart
add_hook("ClientAreaPageCart", 1, function($vars){
	GLOBAL $_LANG;
    
    // Cart -> Product Configuration
    if ($vars['action'] === "confproduct"){
        foreach ($vars['configurableoptions'] as $index => $option){
            if (!empty($_LANG["configoptiondesc".$option['id']])) {
		$vars['configurableoptions'][ $index ]['optionname'] = $option['optionname'].'<br>'.Lang::trans("configoptiondesc".$option['id']);
            }
        }
        
        return array("configurableoptions" => $vars['configurableoptions']);
    }
    
});

in the above example, i've only modified them on the product configuration page...

<?php
$_LANG['configoptiondesc36'] = "<small>Adds our company name to your servername for a small discount. <a href=\"http://www.google.com\" data-toggle=\"tooltip\" title=\"Link To Google\">Special Link</a></small>";

6X6WgKa.png

if you wanted to use the same descriptions/links for all languages, you could either copy&paste the override strings into the other language overrides - or probably easier, create an array of descriptions/links in the hook and bypass using Language Overrides entirely.

Link to comment
Share on other sites

  • 1 month later...

Thanks Brian. I might go this route in future.

@sentq this works fine. However, if you add a product for a client in the admin area (ordersadd.php) the raw html is shown. It doesn't really matter because the client never sees it. But if it can be pretty'd up in the hook, why not? :)

When viewing a product in the admin area the links work fine.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated