Magento 2
  • Personalization for Magento 2
  • Installing
  • Disconnecting
  • Uninstalling
  • Getting Started
  • Configuring
  • Hyvä Theme
  • Guides
    • Migrating to Magento2
    • Upgrading to >= 4.0.0
    • Varnish & Full-Page Caches
    • Advanced User Guide
    • Managing Blocks
    • Overriding or Extending Functionalities
      • Overriding Product Data
        • Excluding Products
        • Customising Pricing
        • Customising Categories
        • Resizing Images
      • Overriding Customer Data
    • Console Commands
    • Tagging Providers
  • Features
    • Product data caching
      • Built-in caching
      • Database caching
    • Variations (Configurable Products)
    • Add to Cart
    • Indexer
      • On 7.x
      • On 5.x and 6.x
      • On 4.x
      • On 3.x
    • Customer Group Pricing
    • Supplier Cost & Inventory Level
    • Restore Cart Link
    • Ratings & Reviews
    • Multi Currency (Exchange Rates)
    • Marketing permission and GDPR compatibility
    • Content Staging & Special Prices
  • Integrations
    • Using Yotpo
  • FAQ
  • Developing & Contributing
  • Visit Nosto
  • Issues
  • Releases
  • Addons
    • Multi Source Inventory (MSI)
      • Installing
      • Uninstalling
      • Configuring
    • Category Merchandising (CM 1.0)
      • Installing
      • Uninstalling
      • Configuring
      • Guides
        • Translating Frontend Strings
        • PWA Implementation
        • Using Elasticsearch
        • Segmentation
        • Overriding or Extending Functionalities
          • Customize Query Parameters
          • Customize Page Size Limit
          • Customize Exclude Filters
        • Debugging
Powered by GitBook
On this page

Was this helpful?

  1. Guides
  2. Overriding or Extending Functionalities
  3. Overriding Product Data

Customising Categories

PreviousCustomising PricingNextResizing Images

Last updated 3 years ago

Was this helpful?

If your store uses a customized logic for handling product's categories you might need to amend categories in Nosto module as well . Start by reading and .

If overriding the product data directly does not seem the best option for you, you can create a service class and make use of Dependency Injection pattern.

Create a new class which will implement CategoryServiceInterface. Override the required functions and afterwards replace CategoryServiceInterface with MyCategoryServive in the DI etc/di.xml

File app/code/My/Nosto/Model/Service/MyCategoryServive.php

<?php

namespace My\Nosto\Model\Service;

use Nosto\Tagging\Model\Service\Product\Category\CategoryServiceInterface;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Product;
use Magento\Store\Api\Data\StoreInterface;

class MyCategoryServive implements CategoryServiceInterface
{   

    /**
     * Method used to return a single category string for given category object
     * @param Category $category
     * @param StoreInterface $store
     * @return null|string
     */
    public function getCategory(Category $category, StoreInterface $store) {
        //ToDo Implement logic    
    }   

    /**
     * Method used to return list of strings representing categories for a given product 
     * @param Product $product
     * @param StoreInterface $store
     * @return array
     */
    public function getCategories(Product $product, StoreInterface $store) {

    }   
}

File app/code/My/Nosto/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Nosto\Tagging\Model\Service\Product\Category\CategoryServiceInterface" type="My\Nosto\Model\Service\MyCategoryServive"/>
</config>
how to extend Nosto module
how to alter Nosto product data