Jump to content

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?

Link to comment
Share on other sites

  • 1 month later...

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)
Link to comment
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
Link to comment
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
Link to comment
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?

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

  • 3 months later...

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.

Link to comment
Share on other sites

  • 6 months later...

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

Link to comment
Share on other sites

  • 9 months later...
  • 1 year later...
  • 1 year later...

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

Link to comment
Share on other sites

  • 4 months later...
  • 4 weeks later...
×
×
  • Create New...