Jump to content

Please help! How substitute $this->errors[] with a fancybox?


l.zuccarini

Recommended Posts

Dear Sir, please help me. I am becoming crazy. I would like change the mode of displaying errors with customers.

 

In many php files there are the code similar that...

 

$this->errors[] = Tools::displayError('errors bla bla bla bla', true);

 

I would like use a fancybox for display the errors... Someone can help me please?

 

In attached file a little example of actual mode for displayerrors...

 

I am using ps 1.5.3.1

 

Thank you.

post-424010-0-59514400-1375108527_thumb.jpg

Link to comment
Share on other sites

  • 1 month later...

can you show any live example of error like this? to be honest, i don't know where error like this appear, it's first time when i see it.

 

the problem with this may be related to the fact, that this popup is usually called from .js file (not from .php!)

Link to comment
Share on other sites

Dear vekia,

in the first thank you for your interesting.

Maybe I wasn't clearly to explain.... 

 

I customized my prestashop, suggesting to customers the right quantity to add in the cart in order to minimize the delivery cost. To do that i modified the file CartController.php

 

for example: 

When a customer try to add a quantity more than max quantity permitted an error will displayed with below code.

if (($cart_quantity + $this->qty) > $max_quantity)
 {
   $this->errors[] = Tools::displayError("Puoi comprare fino a \n".$max_quantity.' di questo prodotto.', true);
 }

All works fine! My goal of this topic it's understand how use fancybox instead of "Tools::displayError" to comunicate with customer. 

Fancybox it's more elegant than "displayErrror"

 

I hope that you understand me.

 

Thank you in advance.

Link to comment
Share on other sites

The $this->errors[] (array of errors) puts the error available for the View to render so you need in the tpl some html code to layout the error. This is done including the errors.tpl in each template, which is a div

{if isset($errors) && $errors}
    <div class="error alert alert-error clearfix">
        <p>{if $errors|@count > 1}{l s='There are %d errors' sprintf=$errors|@count}{else}{l s='There is %d error' sprintf=$errors|@count}{/if}</p>
        <ol>
        {foreach from=$errors key=k item=error}
            <li>{$error}</li>
        {/foreach}
        </ol>
        {if isset($smarty.server.HTTP_REFERER) && .......etc}
            <p class="lnk"><a class="btn btn-inverse" href="{$smarty.server.HTTP_REFERER|escape:'htmlall':'UTF-8'|secureReferrer}" title="{l s='Back'}">« {l s='Back'}</a></p>
        {/if}
    </div>
{/if}

For example in product.tpl at the very beginning you have the include

{include file="$tpl_dir./errors.tpl"}
{if $errors|@count == 0}
<script type="text/javascript">
// <![CDATA[

You can modify the errors.tpl to use a more sophisticated layout than a div.

Edited by Enrique Gómez (see edit history)
Link to comment
Share on other sites

Dear Enrique Gomez,

thank you for your reply.

You have been clearly. But my difficutl it's how use fancybox for show the error message... I know php, html, etcc... But I have not confidence with fancybox. 

 

Can you provide me a little example please?

for example I'd like show a text "hello word" in fancybox when I add any product in the cart.

 

Thank you in advance. 

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