Jump to content

Product Page Error


tekexplore

Recommended Posts

The recently viewed products are stored in PrestaShop's cookie, whether or not the customer is logged in. I don't know why they wouldn't work, unless cookies aren't working on your site, but then customers wouldn't be able to log in at all.

Link to comment
Share on other sites

By default, the "In the same category" gets 30 products in the same category. You could try reducing that number. For example, change line 51 of modules/productscategory/productscategory.php from:

$sizeOfCategoryProducts = $category->getProducts(intval($cookie->id_lang), 1, 30, NULL, NULL, true);



to:

$sizeOfCategoryProducts = $category->getProducts(intval($cookie->id_lang), 1, 10, NULL, NULL, true);



and lines 84-89 from:

// If products tab higher than 30, slice it
if ($sizeOfCategoryProducts > 30)
{
   $categoryProducts = array_slice($categoryProducts, $middlePosition - 15, 30, true);
   $middlePosition = 15;
}



to:

// If products tab higher than 10, slice it
if ($sizeOfCategoryProducts > 10)
{
   $categoryProducts = array_slice($categoryProducts, $middlePosition - 5, 10, true);
   $middlePosition = 5;
}

Link to comment
Share on other sites

I tired your code now the page gets loaded with Products Category module but its taking huge time(>1 Min) to load the product page. Any comments??

Also Kindly see to the attachment which this thread. I got the error message when I tried to import products to the shop I dont know why so many products were not able to load into the store though all single and double quotes in all names and descriptions i mentioned as HTML Ascii code so that it wont clash with MySQL Syntax. Any fix for this?

Import_Error.pdf

Link to comment
Share on other sites

I can't reproduce the problem with the "In the same category" module, but I don't have a huge number of products in any one category. It is the SQL query in the getProducts() function of classes/Category.php that gets the products. I guess it isn't efficient for huge catalogs. Perhaps it would be more efficient to split it into two queries, one that gets selects the categories and then one that joins all the tables together, instead of the current single query that joins all the tables together, then selects the categories.

The reason those product names are failing may be because they are longer than 128 characters, which is the maximum a product name is allowed to be, or they have symbols that are not allowed. What version of PrestaShop are you using? I'm using PrestaShop v1.3.1 and looking at the code, only <>;=#{} are not allowed. It seems many of those failed named have an ' or : though. If you are using an older version of PrestaShop, perhaps one of them is being disallowed.

Link to comment
Share on other sites

I will try by modifying the query for "In the same category" as you said; and for the import issue, I am using latest stable version and many products with : is imported and also for ` i have converted to HTML code and then imported.

How do I change the character limit for Product Name. and what will be the best solution for me to upload product with :, ;, [] characters.

Link to comment
Share on other sites

In my PrestaShop v1.3.1 installation, It is the isCatalogName() function in classes/Validate.php that checks for invalid characters in the product name:

return preg_match('/^[^<>;=#{}]*$/ui', $name);



You can change it to the following to allow ; in your product names:

return preg_match('/^[^<>=#{}]*$/ui', $name);



To change the character limit is difficult. You will need to edit your database using phpMyAdmin and increase the size of the 'name' field in the 'ps_product' table from 128 to however many characters you need. Then edit classes/Product.php and change line 188:

'meta_title' => 128, 'link_rewrite' => 128, 'name' => 128, 'available_now' => 255, 'available_later' => 255);



Change the 128 after 'name' to the maximum number of characters you changed the name to be in the database.

Link to comment
Share on other sites

I want the value price with tax value in smarty I am calling all values from product object from PHP in foreach loop.

Also I have one more query.

In home page I implemented JQuery Tabs to each category for featured products now I want to display featured product for each category separately how to achieve this.

Now I am using

$category = new Category(1);

$products = $category->getProducts(1, 1, 6);
$smarty->assign(array('products' => $products, 'homeSize' => Image::getSize('home')));



This returns all the homefeatured products under all categories but I need for specific category.

Link to comment
Share on other sites

Try the following:

$categories = Category::getSimpleCategories($params['cookie']->id_lang);
$products = array();

foreach ($categories as $category)
{
  $categoryObj = new Category($category['id_category'], $params['cookie']->id_lang);
  $products[$category['id_category']] = $categoryObj->getProducts($params['cookie']->id_lang, 1, 6);
}

$smarty->assign(array('cat_products' => $products, 'homeSize' => Image::getSize('home')));



This code will get the first 6 products from every category. You can then use code like the following in homefeatured.tpl:

{foreach from=$cat_products key=id_category item=products}


     {foreach from=$products item=product}
Product code goes here
     {/foreach}


{/foreach}

Link to comment
Share on other sites

Cool. Found the issue and fixed thanks a ton. I have few queries.

1. I want to mask the "Your Address" section from the registration page. I want to get only Email and Password alone in registration time remaining fields can be updated at any time from My Profile page

2. I want to have the friendly URL as /ean13-title-reference.html not like /id_product-title-reference.html How can I achieve this.

Link to comment
Share on other sites

1. You will need to comment out all the address code in authentication.php and authentication.tpl. Change lines [spam-filter]131 of authentication.php (in PrestaShop v1.3.1) to:

/*        $address = new Address();
       $address->id_customer = 1;
       $errors = array_unique(array_merge($errors, $address->validateControler()));
       if (!sizeof($errors))
       {
           if (!$country = new Country($address->id_country) OR !Validate::isLoadedObject($country))
               die(Tools::displayError());
           if (intval($country->contains_states) AND !intval($address->id_state))
               $errors[] = Tools::displayError('this country require a state selection');
           else
           {
*/                $customer->active = 1;
               if (!$customer->add())
                   $errors[] = Tools::displayError('an error occurred while creating your account');
               else
               {
/*                    $address->id_customer = intval($customer->id);
                   if (!$address->add())
                       $errors[] = Tools::displayError('an error occurred while creating your address');
                   else
                   {
*/                        if (!Mail::Send(intval($cookie->id_lang), 'account', 'Welcome!', 
                       array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => Tools::getValue('passwd')), $customer->email, $customer->firstname.' '.$customer->lastname))
                           $errors[] = Tools::displayError('cannot send email');
                       $smarty->assign('confirmation', 1);
                       $cookie->id_customer = intval($customer->id);
                       $cookie->customer_lastname = $customer->lastname;
                       $cookie->customer_firstname = $customer->firstname;
                       $cookie->passwd = $customer->passwd;
                       $cookie->logged = 1;
                       $cookie->email = $customer->email;
                       Module::hookExec('createAccount', array(
                           '_POST' => $_POST,
                           'newCustomer' => $customer
                       ));
                       if ($back)
                           Tools::redirect($back);
//                    }
               }
//            }
//        }

Link to comment
Share on other sites

and lines 142-211 of authentication.tpl to:

{*    
{l s='Your address'}


{l s='Company'}
           <input type="text" class="text" id="company" name="company" value="{if isset($smarty.post.company)}{$smarty.post.company}{/if}" />



{l s='First name'}
           <input type="text" class="text" id="firstname" name="firstname" value="{if isset($smarty.post.firstname)}{$smarty.post.firstname}{/if}" />
*



{l s='Last name'}
           <input type="text" class="text" id="lastname" name="lastname" value="{if isset($smarty.post.lastname)}{$smarty.post.lastname}{/if}" />
*



{l s='Address'}
           <input type="text" class="text" name="address1" id="address1" value="{if isset($smarty.post.address1)}{$smarty.post.address1}{/if}" />
*



{l s='Address (2)'}
           <input type="text" class="text" name="address2" id="address2" value="{if isset($smarty.post.address2)}{$smarty.post.address2}{/if}" />



{l s='Postal code / Zip code'}
           <input type="text" class="text" name="postcode" id="postcode" value="{if isset($smarty.post.postcode)}{$smarty.post.postcode}{/if}" />
*



{l s='City'}
           <input type="text" class="text" name="city" id="city" value="{if isset($smarty.post.city)}{$smarty.post.city}{/if}" />
*



{l s='Country'}

-
               {foreach from=$countries item=v}
{$v.name|escape:'htmlall':'UTF-8'}
               {/foreach}

*



{l s='State'}

-

*



{l s='Additional information'}
           <textarea name="other" id="other" cols="26" rows="3">{if isset($smarty.post.other)}{$smarty.post.other}{/if}</textarea>



{l s='Home phone'}
           <input type="text" class="text" name="phone" id="phone" value="{if isset($smarty.post.phone)}{$smarty.post.phone}{/if}" />



{l s='Mobile phone'}
           <input type="text" class="text" name="phone_mobile" id="phone_mobile" value="{if isset($smarty.post.phone_mobile)}{$smarty.post.phone_mobile}{/if}" />



{l s='Assign an address title for future reference'} !
           <input type="text" class="text" name="alias" id="alias" value="{if isset($smarty.post.alias)}{$smarty.post.alias}{else}{l s='My address'}{/if}" />
*

*}



2. It's very difficult to do, since PrestaShop rewrites the URL to product.php?id_product=1. The file product.php is expecting a product ID, not an EAN13, and so it won't be able to find the product. You'd need to modify product.php so that it uses the EAN13 to create the product object instead of the product ID. There's a good chance that there is other code that depends on having the product ID in the URL, so you'll probably end up breaking something.

Link to comment
Share on other sites

Cool.. Finally found a solution to implement the friendly URL with out product id its working fine. I have few queries,

1. I have 2 Carriers in backend and assigned to Country INDIA but during checkout process it shows No Carriers Assigned to this country any Fix?
2. I have set the product price Round Off at backend but itseems to be not working in front-end display any fix?

Link to comment
Share on other sites

1. Go to the Shipping tab, select the carrier in the dropdown, then click "Save". If you forget to save the prices for a carrier, you will get that error message.

2. Perhaps the theme is incompatible with your version of PrestaShop. Which theme are you using? Was is designed for PrestaShop v1.3.1 or v1.2.5?

Link to comment
Share on other sites

Check to make sure that the carrier is actually in the zone of the currently-logged-in customer's address. Also, check the "Out-of-range behavior" of the carrier. If that is set to "Disable carrier" and the customer's cart total doesn't fit in any of the ranges, then the carrier will be disabled and you will get that error message. Your ranges should overlap like 0-1, 1-2, etc.

Link to comment
Share on other sites

That's the error message I am talking about. If the carrier is in the zone, the price ranges have been set, and the customer's cart total is in a price range or "Out-of-range behavior" is not set to "Disable carrier", then you shouldn't get that error message. I can't think of anything else that would cause that error message to appear.

Link to comment
Share on other sites

Try the following:

$categories = Category::getSimpleCategories($params['cookie']->id_lang);
$products = array();

foreach ($categories as $category)
{
  $categoryObj = new Category($category['id_category'], $params['cookie']->id_lang);
  $products[$category['id_category']] = $categoryObj->getProducts($params['cookie']->id_lang, 1, 6);
}

$smarty->assign(array('cat_products' => $products, 'homeSize' => Image::getSize('home')));



This code will get the first 6 products from every category. You can then use code like the following in homefeatured.tpl:

{foreach from=$cat_products key=id_category item=products}


     {foreach from=$products item=product}
Product code goes here
     {/foreach}


{/foreach}



Hi, In this code its returning some product under category not Featured Products (Which is marked under Home Category) Any fix?
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...

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