Jump to content

Favourite break shop


Recommended Posts

Hi and welcome. I have a small problem in my favourite code for prestashop 1.4.4.1. Because shop is not working as it should.

 

When it running (the files of favourite are in webserver), it's something wrong with my shop, because once the category, the basket or product view - are empty, and once is all right - it's ok.

 

But when i delete a file that are part of my favourite module, the shop is all right. I don't know what is going wrong.

 

Every time when something wrong i need to clear folder in : tools/smarty/compile.

When the "compile" folder is empty - it's everything's ok - all of page in the shop is ok.

 

The module that I wrote are consists of three files:

- favourites.php (the main folder of shop files)

- FavouriteController.php (in controllers folder)

- favourites.tpl (in theme folder)

 

The sources of files:

1. favourites.php:

<?php
include(dirname(__FILE__).'/config/config.inc.php');
ControllerFactory::getController('FavouriteController')->run();
?>

 

2. FavouriteController.php:

<?php
class FavouriteControllerCore extends FrontController
{
public $php_self = 'favourites.php';

public function setMedia()
{
 parent::setMedia();
 Tools::addCSS(array(_THEME_CSS_DIR_.'favourites.css' => 'all'));
}
public function process()
{
 global $cookie;
 $id_customer = $cookie->id_customer;
 if ($id_customer == 0 or $id_customer == null) {
  echo '<script type="text/javascript">location.href="http://belleju.com/my-account"</script>';
 } else {
  $id_lang = self::$cookie->id_lang;
  if (isset($_GET['add'])) {
   $insert = Db::getInstance()->ExecuteS('INSERT INTO '._DB_PREFIX_.'favourites SET '
   .' id_product = "'.$_GET['add'].'", id_customer = "'.$id_customer.'", date_add = "'.date('Y-m-d').'" ');
  }
  if (isset($_GET['del'])) {
   $ids = explode(':', $_GET['del']);
   Db::getInstance()->ExecuteS('DELETE FROM '._DB_PREFIX_.'favourites WHERE id_product = "'.$ids[1].'" AND id_customer = "'.$ids[0].'"');
  }

  $sql = Db::getInstance()->executeS('SELECT DISTINCT p.id_product , pl.name , p.price , pl.link_rewrite , il.id_lang , il.id_image ,
  CONCAT(p.`id_product`, \'-\', i.`id_image`) as imageUrl,
  (SELECT `sign` FROM '._DB_PREFIX_.'currency WHERE id_currency="'.(isset($_COOKIE['id_currency']) ? $_COOKIE['id_currency'] : 4).'") AS sign,
  pl.`name`, i.`id_image`, tax.rate, (p.price * (1+(rate/100))) AS price FROM `'._DB_PREFIX_.'favourites` fp
  LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = fp.`id_product`)
  LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.')
  LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`)
  LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
  LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
  LEFT JOIN '._DB_PREFIX_.'tax_rule AS trule ON (p.id_tax_rules_group = trule.id_tax_rules_group)
  LEFT JOIN '._DB_PREFIX_.'tax AS tax ON (trule.id_tax = tax.id_tax) WHERE fp.id_customer = '.(int)$id_customer.'');
  self::$smarty->assign('favPro', $sql);
 }
}

public function displayContent()
{
 parent::displayContent();
 self::$smarty->display(_PS_THEME_DIR_.'favourites.tpl');
}
}
?>

 

3. favourites.tpl

<h1>{l s='Favourites'}</h1>
<ul id="product_list" class="clear">
{foreach from=$favPro item=product name=products}
<li class="ajax_block_product" onmouseover="document.getElementById('x'+{$product.id_product}).style.visibility='visible'" onmouseout="document.getElementById('x'+{$product.id_product}).style.visibility='hidden'">
<a id="x{$product.id_product}" href="favourites.php?del={$cookie->id_customer}:{$product.id_product}" style="visibility:hidden;position:absolute;float:right;margin-left:148px;margin-top:5px;font:bold 13px Tahoma;color:#c00;text-decoration:none">x</a>
<a href="product.php?id_product={$product.id}" class="product_img_link">
 <img src="{$link->getImageLink($product.link_rewrite, $product.imageUrl, 'home')}" alt="" /></a>
 <h3><a href="{$product.link}">{$product.name}</a></h3>
 <p class="price">{l s='price'}
   <span>
 {$product.price|string_format:"%.2f"} {$product.sign}
   </span>
 </p>
</li>
{if $product@iteration % 4 == 0} <div style="clear:both;float:left;"> </div>{/if}
{foreachelse}
<p class="empty"> {l s='result empty'} </p>
 {/foreach}
</ul>

 

Please help me, because I don't know what's wrong.

 

Best regards.

Link to comment
Share on other sites

×
×
  • Create New...