Oro Documentation
Oro Documentation
  • USERS
  • DEVELOPERS
    • Backend Developer Guide
    • Frontend Developer Guide
    • Community Guide
  • CLOUD
  • BLOG
  • FORUM
  • Home >
  • Developer Documentation >
  • Backend Developer Guide >
  • Bundles Documentation >
  • OroProductBundle >
  • Related Items
  • Backend Developer Guide
    • Setup
      • System Requirements
        • Performance Optimization
        • MySQL Optimization
      • Development Environment
        • Environment Setup for Community Edition
        • Environment Setup for Enterprise Edition
        • Web Server Configuration
        • Healthcheck and Data Monitoring
      • Demo Environment
        • VM VirtualBox
        • AWS Cloud Platform
        • Vagrant Provision
      • Installation
      • Installation in Sub-Folder
      • Loading Demo Data
      • Launch
      • Upgrade
      • Reinstall
      • Protect Cookies
    • Application Architecture
      • Technology Stack
        • Database
        • Search Index
          • ORM Search Engine
          • Elasticsearch
        • Message Queue
      • Application Structure
      • Application Framework
        • Architecture Principles of Oro Applications
      • Application Customization
      • Differences to Common Symfony Applications
      • Custom Oro Application
    • Bundles and Extensions
      • Create a Bundle
      • Extend an Existing Bundle
      • Install Extension from the Oro Marketplace
      • Add an Extension to Oro Marketplace
    • Entities
      • Create Entities
      • Extend Entities
      • Configure Entities
      • CRUD Operations
      • Data Grids
        • Pass Request Parameters to the Grid
      • Protect Entities Using ACLs
      • Entity Activities
      • Entity Attachments
      • Customize CRUD Pages
      • Customize Data Grid
    • Entities Data Management
      • Fixtures and Demo Data
      • Reports & Segments
      • Search Index
        • Configuration
        • Console Commands
        • Query Builder
        • Best Practices
        • Troubleshooting
      • Workflows
        • Introduction
        • Configuration Reference
        • Elements
        • Basic Configuration
        • Transition Forms
        • Translation Wizard
        • Configuration Example
      • Operations (Actions)
        • Glossary
        • Buttons
        • Action Groups
        • Configuration Reference
        • Actions and Conditions
        • Console Commands
      • Processes
      • Data Audit
    • Security
      • Introduction to Security in Oro Applications
      • Access Levels and Ownership (Example)
    • Translation and Localization
      • Translation
      • Localization
    • Integrations
      • Create an Integration
      • Import and Export Entities
      • Extend Entities to Support Bulk Import and Export
      • Accelerate Import
    • Dashboards
    • Navigation
    • Emails
    • Message Queue
      • Message Queue Jobs
      • Consumer
        • Resetting Container
      • Security Context
      • Logging, Error Handling and Debugging
        • Writing Logs to ELK Stack
      • Testing
      • RabbitMQ (Enterprise Edition Only)
        • Command Lines
        • Divide Queue to Separate Queues
        • Configure RabbitMQ for Production
        • Backup and Restore
        • Troubleshooting
      • Supervisord
    • Cron
    • WebSocket Notifications
      • Websocket Recipes
        • Use Maintenance Mode Notifications in Oro Applications
        • Use Content Outdated Notifications in Oro Applications
        • Create a Topic and a Handler for Publishing and Subscribing
        • Publish Messages to Existing Topics
        • Use Authentication and Authorization in WebSocket Connections
      • WebSocket Connection Configuration
    • Scopes
    • Feature Toggle
    • Logging
    • System Configuration
    • Configuration Reference
      • Annotations
        • @Acl
        • @AclAncestor
        • @Config
        • @ConfigField
        • @TitleTemplate
      • YAML
        • Access Control Lists
        • Assets
        • Dashboards
        • Datagrids
        • Entity Configuration
        • Navigation
        • Placeholders
        • Require.JS
        • Search Index
        • System Configuration
        • Workflows
    • Extending OroCRM
      • Add OroCommerce Capabilities to an OroCRM Application
    • Extending OroCommerce
      • Payment Methods
      • Shipping Methods
    • Akeneo Integration
    • Automated Tests
      • Functional Tests
      • Behat Tests
    • API Developer Guide
      • Using Web Services API
        • WSSE Authentication
        • Simple Search API
        • Advanced Search API
      • Actions
      • CLI Commands
      • Configuration Extensions
      • Configuration Extras
      • Configuration Reference
      • Documenting API Resources
      • Forms and Validators Configuration
      • Headers
      • Filters
      • How to
      • Processors
      • Configure Stateless Security Firewalls
      • Testing REST Api
      • Request Type
      • CORS Configuration
      • Entity Aliases
    • Bundles Documentation
      • OroActionBundle
      • OroActivityBundle
      • OroActivityListBundle
      • OroAddressBundle
      • OroApiBundle
      • OroAssetBundle
      • OroAttachmentBundle
        • OroAttachmentBundle Configuration
      • OroBatchBundle
      • OroCacheBundle
        • Cache in Oro Application
      • OroCalendarBundle
      • OroChartBundle
      • OroCommentBundle
      • OroConfigBundle
      • OroCronBundle
      • OroCurrencyBundle
      • OroDashboardBundle
      • OroDataAuditBundle
      • OroDataGridBundle
      • OroDistributionBundle
      • OroEmailBundle
      • OroEmbeddedFormBundle
      • OroEntityBundle
      • OroEntityConfigBundle
      • OroEntityExtendBundle
      • OroEntityMergeBundle
      • OroEntityPaginationBundle
      • OroEntitySerializedFieldsBundle
      • OroFeatureToggleBundle
      • OroFilterBundle
      • OroFormBundle
      • OroGaufretteBundle
      • OroGridFSConfigBundle
      • OroImapBundle
      • OroImportExportBundle
      • OroInstallerBundle
      • OroIntegrationBundle
      • OroLayoutBundle
        • Layout Cache
      • OroLocaleBundle
      • OroLoggerBundle
      • OroMessageQueueBundle
      • OroMigrationBundle
      • OroNavigationBundle
      • OroNoteBundle
      • OroNotificationBundle
      • OroOrganizationBundle
      • OroPlatformBundle
      • OroQueryDesignerBundle
      • OroRedisConfigBundle
      • OroReportBundle
      • OroRequireJSBundle
      • OroScopeBundle
      • OroSearchBundle
      • OroSecurityBundle
      • OroSegmentBundle
      • OroSidebarBundle
      • OroSyncBundle
      • OroTagBundle
      • OroTestFrameworkBundle
        • Additional Doctrine Events
      • OroThemeBundle
      • OroTranslationBundle
      • OroTwigInspector
      • OroUIBundle
        • Action Manager
        • Client Side Navigation
        • Content Providers
        • Dynamic Assets
        • Formatters
        • Scroll Data Customization
        • TWIG Placeholders
        • TWIG Filters
        • Widgets
        • ApiAccessor
        • BaseClass
        • HiddenInitializationView ⇐ BaseView
        • Layout Subtree View
        • LoadMoreCollection
        • Loading Mask View
        • MultiUseResourceManager ⇐ BaseClass
        • PersistentStorage
        • Highlight Text View
        • RouteModel
        • RoutingCollection
        • SearchApiAccessor
        • Viewport Manager
        • Error Handler
        • Input Widgets
        • Items Manager
        • Mediator Handlers
      • OroWindowsBundle
      • OroWorkflowBundle
      • OroCatalogBundle
      • OroCheckoutBundle
      • OroCMSBundle
        • Content Blocks
        • Widgets on a CMS Content Page
      • OroCustomerBundle
      • OroFrontendBundle
      • OroInventoryBundle
      • OroOrderBundle
      • OroPayPalBundle
      • OroPricingBundle
        • Configure Price List Sharding
        • Optimize Website Indexation and Price Recalculation
        • Combined Price List
        • Price Storage
        • Pricing Strategy
      • OroProductBundle
        • Product Actions
        • Customize Products Using Layouts
          • Customize Product View Page
          • Customize Product List Page
          • Customize Products SKU Validation
        • Product Attributes
        • Product Unit Formatting
        • Product Variant Search
        • Related Items
      • OroSEOBundle
        • Sitemap
        • SEO Meta Fields
      • OroTaxBundle
      • OroWebCatalogBundle
      • OroWebsiteSearchBundle
Version:
3.1
  • 4.1
  • 4.2 (latest)
  • 5.0 Alpha 1 (master)
  • Contents
    • Classes
      • Config provider
      • Strategies
        • Finder Strategy
        • Assigner Strategy

Related Items

Usually, when you sell a product you also offer your customers some related products that are a tempting or useful add-on to the product. For example, if you are selling phones, it is good to show fitting accessories next to it. This is where the Related Items functionality comes handy.

Classes

Config provider

Class Oro\Bundle\ProductBundle\RelatedItem\AbstractRelatedItemConfigProvider provides you with the configuration for Related Items.

Example:

You can find example in Oro\Bundle\ProductBundle\RelatedItem\RelatedProductRelatedProductsConfigProvider.

Here is the quick overview of its usage:

isEnabled()

1
$this->get('oro_product.related_item.related_product.config_provider')->isEnabled();

Returns information on whether the Related Items functionality is enabled.

getLimit()

1
$this->get('oro_product.related_item.related_product.config_provider')->getLimit();

Returns integer describing how many related products can be assigned for one product.

isBidirectional()

1
$this->get('oro_product.related_item.related_product.config_provider')->isBidirectional();

Returns information about the relation type. To illustrate the difference between uni- and bidirectional relation, let us consider the following example. Product B is a related item of Product A. If bidirectional attribute value is set to true, the product A is also considered as related item of Product B (see [Strategy](#strategy)). This does not apply when the relation is not bidirectional.

When viewing product A in the storefront, a buyer can always see the Product B in related items. When viewing product B in the storefront, the buyer may or may not see the Product A in related items (depending on the type of relationship).

isBidirectional == True and Product B is a related item of Product A

Product Related Items
Product A Product B
Product B Product A

isBidirectional == False and Product B is a related item of Product A

Product Related Items
Product A Product B
Product B None

For more information about configuration see OroConfigBundle.

Strategies

Finder Strategy

The finder strategy (Oro\Bundle\ProductBundle\RelatedItem\FinderStrategyInterface) provides related products for a user. You can see a simple example in Oro\Bundle\ProductBundle\RelatedItem\RelatedProduct\AssignerDatabaseStrategy where related products are fetched from the database. This strategy takes into account the configuration from the Config Provider.

For more complex logic, you can create your own strategy.

For this, implement Oro\Bundle\ProductBundle\RelatedItem\Strategy\StrategyInterface, overload or decorate its definition: “oro_product.related_products.strategy”, and provide the implementation of the find method:

1
2
3
4
5
 /**
  * @param Product $product
  * @return Product[]
  */
 public function find(Product $product);

where $product is a Product object for which you are searching related products. The method has to return an array of Products.

Assigner Strategy

Oro\Bundle\ProductBundle\RelatedItem\AssignerStrategyInterface Use AssignerStrategyInterface to store the relation between the product and its related item. An example of the implementation can be found in Oro\Bundle\ProductBundle\RelatedItem\RelatedProducts\AssignerDatabaseStrategy.

It defines two methods:

  1. addRelations()

    1
    2
    3
    4
    5
    6
    7
    8
    9
     /**
      * @param Product $productFrom
      * @param Product[] $productsTo
      *
      * @throws \LogicException When functionality is disabled
      * @throws \InvalidArgumentException When a user tries to add a related product to itself
      * @throws \OverflowException When a user tries to add more products than the limit allows
      */
     public function addRelations(Product $productFrom, array $productsTo);
    

    The addRelations method saves the Related Items relations: from $productFrom to every product provided in $productsTo. The following exceptions may be thrown:

    • LogicException should be thrown when Related Items functionality is disabled.
    • InvalidArgumentException should be thrown, when a user tries to add product as a related item for itself.
    • OverflowException should be thrown when a user tries to add more products that the configured limit allows.
  2. removeRelations()

    1
    2
    3
    4
    5
     /**
      * @param Product $productFrom
      * @param Product[] $productsTo
      */
     public function removeRelations(Product $productFrom, array $productsTo);
    

    The removeRelations method removes all Related Item relationships between the product provided in $productsTo and the $productFrom product. When a product in $productsTo is not a Related Item of the $productFrom, no exception should be thrown and the invalid relationship should be skipped. Other Related Items relationships should be processed.

Oro Documentation
  • Oro inc
  • Orocommerce
  • Orocrm
  • Oroplatform
  • Partners
  • Services
  • Events
  • Terms & conditions
  • Privacy policy
  • Contributor license agreement

@2021 Oro, Inc. All Rights Reserved.

Back to top