Load category, but only with limited data to build a Breadcrumb

Based on the helper catalog there is a function that returns a path for the breadcrumb to be displayed in Magento when viewing a Product.

I want to enhance this method to return the full path of the categories back to me.

Current implementation:

  ...           if ($  this->getProduct()) {                 $  path['product'] = array('label'=>$  this->getProduct()->getName());             }         $  this->_categoryPath = $  path; 

Here I want to append a process that load the categories of the product via getCategoryIds(), which is available trough the getProduct() method.

I’d like to load a conditional collection, that only loads the respective ID of the categories but only the following data:

  • url
  • name
  • title
  • my_custom_eav_param

I assume something like:

        if ($  product = $  this->getProduct()) {             $  cats = $  product->getCategoryIds();             foreach ($  cats as $  category_id) {                 $  attributesToSelect = [''];                 $  _cat = Mage::getModel('catalog/category')                     ->getCollection()                     ->addAttributeToSelect('*')                     ->addAttributeToFilter(['name', 'id', 'url', 'description'])                     ->load()                     ->getSelect()->__toString();                 var_dump($  _cat); die;             }             $  path['product'] = array('label'=>$  this->getProduct()->getName());         }          $  this->_categoryPath = $  path; 

but this does not work. How can I specify what entities are loaded in order to keep load to DB as low as possible for this requests? To load the whole category all the time is a lot of traffic, or can it be ignored completely?

Redirect Search link to specific Category search

I simply want to redirect all search link on my post to custom category search.

E.g I have a category named wordpress, and posts on the category already contains links to search example.com/search/keyword/ I want it to be redirected to example.com/wordpress/?s=keyword

Is there anyway to achieve this Please help me out.

Thanks in advance

Magento REST API Post Product and Category without “Sorting” parameter

I need to POST products with their category number, but without their sorting because I dont want to change the sorting via API.

{"product": {     "id": 1234,     "sku": "2345",     "name": "Nice Product",     "extension_attributes": {         "website_ids": [1],         "category_links": [{             "position": 11,             "category_id": "123"         }]     }} } 

As soon as I take our the sorting I get an error.

How to separate WooCommerce category and product page for showcase and shop?

I want to separate WooCommerce category and product page for showcase and shop without create double products and category.

I set /category/ in permalink settings for showcase,

Ex. /category/male /category/female 

where male/female WooCommerce product category

Now I want separate shop with url like this,

/shop/male /shop/female 

with same product category

Does it possible without create duplicate category?

If anyone has any advice that would be greatly appreciated.

Add custom category name as data-filter to switch between these categories

I have a portfolio page where I would like to place three buttons that will switch between different categories. I am using data-filer to sort them into different projects. I am thinking, how can I give this data-filter a category name, so it would switch depending what category and also when adding new post (project) and using any custom category, it would place it right in that portfolio section.

For this page I have this code:

<?php  get_header(); ?>   <div class="container projects-container">  <div class="gallery-nav" align="center">    <button class="btn btn-default filter-button gallery-link" data-filter="all">All</button>    <button class="btn btn-default filter-button gallery-link" data-filter="architecture">Architecture</button>    <button class="btn btn-default filter-button gallery-link" data-filter="furniture">Furniture</button>   </div>   <div class="row">    <?php    $  subs = new WP_Query(      array(        'post_parent' => $  post->post,        'post_type' => 'post',        'meta_key' => '_thumbnail_id'      )   );   if( $  subs->have_posts() ) :      while( $  subs->have_posts() ) :        $  subs->the_post(); ?>    <div class="col-sm-12 col-md-6 col-lg-4 cover-img filter">         <a href="<?php the_permalink(); ?>">       <?php the_post_thumbnail('post-thumbnail', ['class' => 'img-fluid']); ?></a>   </div>   <?php endwhile; ?>  <?php endif; ?>  <?php get_footer(); 

And this jQuery code:

jQuery(document).ready(function(){    $  (".filter-button").click(function(){       var value = $  (this).attr('data-filter');        if(value == "all")       {           $  ('.filter').show('1000');       }       else       {          $  (".filter").not('.'+value).hide('3000');         $  ('.filter').filter('.'+value).show('3000');        }   });    if ($  (".filter-button").removeClass("active")) {    $  (this).removeClass("active");    }    $  (this).addClass("active");  }); 

Magento 2 category updated programmatically not updated in admin

I am creating and updating the category programmatically from the admin area, while I create the category it’s showing in front-end and back-end but while updating the details, it’s reflecting in front-end but not in the backend.

$  websiteId = $  this->_storeManager->getWebsite()->getWebsiteId(); $  store = $  this->_storeManager->getStore(); $  storeId = $  store->getStoreId();  $  categoryFactory = $  this->_objectManager->get('Magento\Catalog\Model\CategoryFactory'); $  categoryRepository = $  this->_objectManager->get('\Magento\Catalog\Api\CategoryRepositoryInterface'); $  categoryCollection = $  categoryFactory->create()->getCollection()->addAttributeToFilter('entity_id', $  data['id'])->setPageSize(1); if ($  categoryCollection->getSize()) {     $  categoryId = $  categoryCollection->getFirstItem()->getEntityId();      $  category = $  categoryRepository->get($  categoryId, 0); } else {     $  category = $  categoryFactory->create(); } $  category->setStoreId((int)$  storeId); $  category->setName($  data['name']); if ($  isParent) {     $  category->setParentId(2); } else {     $  categoryCollection = $  categoryFactory->create()->getCollection()->addAttributeToFilter('entity_id', $  data['parent_id'])->setPageSize(1);     if ($  categoryCollection->getSize()) {         $  categoryId = $  categoryCollection->getFirstItem()->getEntityId();         $  category->setParentId($  categoryId);     }  } $  category->setIsActive($  data['is_active']); $  category->setIsAnchor($  data['is_anchor']); $  category->setIncludeInMenu($  data['include_in_menu']); $  category->setCustomUseParentSettings($  data['custom_use_parent_settings']);  // will set meta details foreach ($  this->additionalHeaders as $  header) {     if (array_key_exists($  header, $  this->headersMap)) {         $  additionalData[$  header] = $  data[$  this->headersMap[$  header]];     } } $  category->setCustomAttributes($  additionalData); $  categoryRepository->save($  category); 

for your further information Ienter image description here have updated the screens, kindly check and let me share your ideas and thoughts, thanks in advance for your support

enter image description here