Jump to content
sumitt2004

Category Links are going 404

Recommended Posts

Hi,

 

I am facing a strange issue with PS 1.5.3.1, when I installed PS then I choose demo products with computer theme. By default there were 3 categories Laptop, iPod and Accessories I deleted 2 categories (except Laptop) and added few more. Now only one (Laptop) link is working all new added categories links are going to 404. I tried below steps:

 

1. Checked all categories are Enabled.

2. All new categories are linked with Home.

3. In category controller I check code which is redirecting the link and found that

!$this->category->inShop() is returning true. in below code.

 

public function canonicalRedirection($canonicalURL = '')
{
 if (!Validate::isLoadedObject($this->category) || !$this->category->inShop() || !$this->category->isAssociatedToShop())
 {
  $this->redirect_after = '404';
  $this->redirect();
 }
 if (!Tools::getValue('noredirect') && Validate::isLoadedObject($this->category))
  parent::canonicalRedirection($this->context->link->getCategoryLink($this->category));
}

 

Could anybody please help me get rid from this?

Share this post


Link to post
Share on other sites

Hi,

 

I am facing the exact same problem. The only thing different from sumitt2004 is that I have imported about 1000 products via CSV from an old setup of Prestashop (1.3.x).

 

public function canonicalRedirection($canonicalURL = '')
{
 var_dump(Validate::isLoadedObject($this->category)); // true
 var_dump($this->category->inShop()); // false
 var_dump($this->category->isAssociatedToShop()); // true
 if (!Validate::isLoadedObject($this->category) || !$this->category->inShop() || !$this->category->isAssociatedToShop())
 {
  echo "it's coming here";
  exit;
  $this->redirect_after = '404';
  $this->redirect();
 }
 if (!Tools::getValue('noredirect') && Validate::isLoadedObject($this->category))
  parent::canonicalRedirection($this->context->link->getCategoryLink($this->category));
}

 

Everything works fine-ish in the BO.

Edited by digitalis (see edit history)

Share this post


Link to post
Share on other sites

Mmm... I fixed it. I don't know if this quick-hack is safe though.

 

In Category class:

 

 

public function inShop(Shop $shop = null)
{
if (!$shop)
 $shop = Context::getContext()->shop;

if (!$interval = Category::getInterval($shop->getCategory()))
 return false;

return ($this->nleft >= $interval['nleft'] && $this->nright <= $interval['nright']);
}

 

It turns out that the value nright from the home category wasn't big enough after the import and I just changed it to 200. Does it make sense?

  • Like 1

Share this post


Link to post
Share on other sites

I guess I won't have problems with this solution since I only run one shop. If someone reads this and is interested the multishop feature don't try what I just said in the post above and wait until someone more experienced gives a more adequate solution.

Edited by digitalis (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

Digitalis,

 

Your fix did work for me too I was looking for so long for a fix couldn't find it. I've got 3000+ products in the database so I hope this won't cause any issues with loading times.

 

Anyways why did you pick 200? If I intend to have 5000+ products in the database would 200 still be alright to use in your opinion?

Share this post


Link to post
Share on other sites

Hi Bteo,

 

I picked 200 since this shop I am working on has about 150~ categories, so AFAIK it doesn't have much to do with the amount of products your store has but the number of categories.

 

Then again, I am really newbie to PrestaShop. I'd wait and see if someone more experienced with PS can help with this issue.

Share this post


Link to post
Share on other sites

Did you try to turn off the cache option in Advanced Preferences->Performance.

 

Category links are being cached, and will not update if the cache is active.

Share this post


Link to post
Share on other sites

Did you try to turn off the cache option in Advanced Preferences->Performance.

 

Yes, I did. That didn't seem to be the problem at least in my case.

Share this post


Link to post
Share on other sites

I've got 400 categories but still worked for me.

 

Also its not a cache problem. I believe the problem is the importing via csv. Could be a bug with prestashop.

 

When importing via csv I noticed in mysql under the Products section the

 

nleft & nright fields are 0

 

Every other category / sub category in the database has numbers in this field except the ones I've imported via csv.

Share this post


Link to post
Share on other sites

Ok found the fix its in

 

Lopcalization > Countries > EDIT COUNTRY

 

You can change the display order of address, state, etc...

Share this post


Link to post
Share on other sites

I added one new fake category, made home the root directory, saved, and now every other category links to the correct products. It also made the downward arrow appear near the Category title like it should be.

Edited by paperpast (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

I get this damn bug any time I have to take an order from a customer over the phone from a different country. I have to log out as that customer and I think reselect English as my localization and maybe force template recompile.........I'm not sure, but there's a magical process that I'll make note of next time it happens, but I mostly wildly click on crap in a mad rush to stop losing freaking orders for a whole damn day. I'd actually pay good money for this software if I could get guarantees it wouldn't blow up from the slightest sneeze.

Share this post


Link to post
Share on other sites

Hi to everybody, i have the same issue on my website  www.iloveisicily.ie -  Products and category are in the database, but on the categories link i get a 404 error.  Also, Prestashop system doesn't show this categories in Breadcrumb, if i use the istant search.  This matter is born with the ultimate upgrade to new version

Share this post


Link to post
Share on other sites

I am also getting problem earlier all is well now whenever i add any any sub categoery it is howing in the backend but in the FO when i click on the sub category it redirects to 404 page

Share this post


Link to post
Share on other sites

Mmm... I fixed it. I don't know if this quick-hack is safe though.

 

In Category class:

 

 

public function inShop(Shop $shop = null)
{
if (!$shop)
$shop = Context::getContext()->shop;

if (!$interval = Category::getInterval($shop->getCategory()))
return false;

return ($this->nleft >= $interval['nleft'] && $this->nright <= $interval['nright']);
}

 

It turns out that the value nright from the home category wasn't big enough after the import and I just changed it to 200. Does it make sense?

Sorry i dont understand what you mean with i just changed it to 200???? Where is it on the code you post it the value?

Or is there a specific place to do that?

 

Thanks

Share this post


Link to post
Share on other sites

Just call anywhere Category::regenerateEntireNtree()

How? I have also 404 categories after csv import. Htaccess regeneration didn't helped.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More