Jump to content

How can I load the content of errors.tpl via AJAX


Recommended Posts

I'm running PrestaShop 1.5.4.1 and I'm trying to display all errors via JavaScript.

 

I customized the .js for the cart so that the notifications for things like adding to cart and errors from the conditional

if (jsonData.hasError)

in the

updateCart

function are consistent.

 

However, if a product is out of stock, a new page is loaded. I want this to remain consistent with the customized .js.

 

I know I could target the button with

{if ${$product_type}.quantity > 0}

, but that wouldn't take care of other potential errors, so would only be a temporary fix.

Link to comment
Share on other sites

I guess I need to figure out why/how the errors.tpl is being called/loaded. I think the it's because of the href in the anchor within the else part of this conditional… I know the easiest thing is to just load that via AJAX, but it feels wrong because I'm not sure this is the only thing that'll be calling that errors.tpl and I want to be consistent site-wide.

{foreach from=$foreach_from item=$foreach_item name=$foreach_name}
 {if ${$product_type}.quantity > 0}
<a href="{$link->getPageLink('cart')}?qty=1&id_product={${$product_type}.id_product}&token={$static_token}&add" class="btn btn-primary ajax_add_to_cart_button" rel="ajax_id_product_{${$product_type}.id_product}">
  {l s='Add to Bag'}
</a>
 {else}
<a href="{$link->getPageLink('cart')}?qty=1&id_product={${$product_type}.id_product}&token={$static_token}&add" class="btn btn-danger" rel="ajax_id_product_{${$product_type}.id_product}" disabled="disabled" data-toggle="tooltip" title="" data-original-title="{l s='Please check back soon.'}">
  {l s='Out of Stock'}
</a>
 {/if}
{/foreach}

 

Here's the whole template, just in case…

{if !isset($product_type)}
 {assign "product_type" "product"}
{/if}
{if !isset($span)}
 {assign "span" "2"}
{/if}
{if !isset($img_size)}
 {assign "img_size" "home_default"}
{/if}[/font]
[font=courier new,courier,monospace]{if !isset($foreach_from)}
 {assign "foreach_from" $products}
{/if}
{if !isset($foreach_item)}
 {assign "foreach_item" "product"}
{/if}
{if !isset($foreach_name)}
 {assign "foreach_name" "products"}
{/if}
{if !isset($conditional)}
 {assign "conditional" "true"}
 {*
This allows me to limit the number of products returned with something like:[/font]
[font=courier new,courier,monospace]		$smarty.foreach.$foreach_name.index < 4
 *}
{/if}[/font]
[font=courier new,courier,monospace]<ul class="thumbnails">
 {foreach from=$foreach_from item=$foreach_item name=$foreach_name}
{if $conditional}
  <li class="span{$span}">
	<div class="thumbnail thumbnail_product">
	  <div class="thumbnail_inner">
		<a href="{${$product_type}.link}">
		  <img src="{$link->getImageLink(${$product_type}.link_rewrite, ${$product_type}.id_image, {$img_size})}" alt="{${$product_type}.name|escape:html:'UTF-8'}">
		</a>
		<div class="price price_tag item_price">
		  {if !$priceDisplay}
			{convertPrice price=${$product_type}.price}
		  {else}
			{convertPrice price=${$product_type}.price_tax_exc}
		  {/if}
		</div>
		{if ${$product_type}.quantity > 0}
		  <a href="{$link->getPageLink('cart')}?qty=1&id_product={${$product_type}.id_product}&token={$static_token}&add" class="btn btn-primary ajax_add_to_cart_button" rel="ajax_id_product_{${$product_type}.id_product}">
			{l s='Add to Bag'}
		  </a>
		{else}
		  <a href="{$link->getPageLink('cart')}?qty=1&id_product={${$product_type}.id_product}&token={$static_token}&add" class="btn btn-danger" rel="ajax_id_product_{${$product_type}.id_product}" disabled="disabled" data-toggle="tooltip" title="" data-original-title="{l s='Please check back soon.'}">
			{l s='Out of Stock'}
		  </a>
		{/if}
		{if isset(${$product_type}.new) && ${$product_type}.new == 1}
		  <small class="new label label-info">{l s='New'}</small>
		{/if}
	  </div>
	  <h2>
		<a href="{${$product_type}.link}">{${$product_type}.name|escape:'htmlall':'UTF-8'}</a>
	  </h2>
	  <h3>
		by
		{* prepend href with "/{$lang_iso}" once we go multi-lingual *}
		<a href="/{${$product_type}.id_manufacturer}_{${$product_type}.manufacturer_name|lower|escape:'url'}">
		  {${$product_type}.manufacturer_name}
		</a>
	  </h3>
	</div>
  </li>
{/if}
 {/foreach}
</ul>

Edited by curtisblackwell (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...