Oro Documentation
Oro Documentation
  • USERS
  • DEVELOPERS
    • Backend Developer Guide
    • Frontend Developer Guide
    • Bundles & Components
    • Web Services API Guide
    • Community Guide
  • CLOUD
  • BLOG
  • ACADEMY
  • Home >
  • Oro Bundles and Components >
  • OroProductBundle >
  • Related Items
  • Oro Bundles and Components
    • Components
      • Configuration Merger
      • Cumulative Resources
      • System Aware Resolver
    • ActionBundle
    • ActivityBundle
      • Commands
    • ActivityListBundle
    • AddressBundle
    • ApiBundle
    • AssetBundle
      • Commands
    • AttachmentBundle
      • OroAttachmentBundle Configuration
      • Displaying Pictures
      • Generating Image and File URLs
      • Image Placeholder Configuration
    • BatchBundle
    • CacheBundle
    • CalendarBundle
      • Calendar Provider
      • Calendar Context Menu
      • System Calendars
      • Workflow Action
      • Recurring Events
      • UID (Unique Calendar Identifier)
      • Calendar Event Ownership
      • Attendees
    • ChartBundle
    • CookieConsentBundle
    • CommentBundle
    • ConfigBundle
    • CronBundle
    • CurrencyBundle
      • Multi Currency Cell Content Editor
    • DashboardBundle
    • DataAuditBundle
    • DataGridBundle
      • Default Editors
    • DistributionBundle
    • DigitalAssetBundle
    • ElasticSearchBundle
      • Index Agent and Search Engine
      • ElasticSearch Indexes Backup
      • ElasticSearch Configuration
      • Request Builders
      • Troubleshooting
      • Upgrade Website Index to Elasticsearch >=7.7, <8.0
    • EmailBundle
      • Transports
      • Events
      • Emails
      • Email Templates
      • Email Templates Migrations
      • System Mailboxes
      • Email Ownership
      • Sending Emails in Workflows and Actions (Operations)
      • Recipients Autocompletion
      • Public and Private Emails
      • Commands
    • EmbeddedFormBundle
    • EntityBundle
      • EntityModel
      • EntitySelectSearchApiAccessor ⇐ SearchApiAccessor
      • EntityStructureDataProvider
    • EntityConfigBundle
    • EntityExtendBundle
    • EntityMergeBundle
    • EntityPaginationBundle
    • EntitySerializedFieldsBundle
    • FeatureToggleBundle
    • FilterBundle
      • Filter Form Types
      • Grid Extension
    • FormBundle
      • Form Components Overview
      • Update Handler
      • Entity Create or Select Form Type
      • Rich Text Form Type
      • Autocomplete Form Type
      • Text Autocomplete Form Type
      • UI DataBlock Config Overview
      • Expression Editor
      • Client Side Validation
      • InlineEditableViewComponent
      • Index of Supported Editors
        • AbstractRelationEditorView
        • TextEditorView
        • NumberEditorView
        • PercentEditorView
        • DateEditorView
        • DatetimeEditorView
        • SelectEditorView
        • MultiSelectEditorView
        • MultiCheckboxEditorView
        • MultiRelationEditorView
        • RelatedIdRelationEditorView
        • RelatedIdSelectEditorView
      • Search APIs
    • GaufretteBundle
    • GridFSConfigBundle
    • ImapBundle
      • Usage Example
      • Synchronization with IMAP Servers
      • OAuth Providers for Mailboxes
      • User Email Origin Transport
    • ImportExportBundle
      • Commands
    • InstallerBundle
      • Commands
    • IntegrationBundle
    • LayoutBundle
      • Layout Cache
    • LocaleBundle
      • Locale Settings
      • Number Formatting
      • Date and Datetime Formatting
      • Name Formatting
      • Address Formatting
      • Localization
      • Managing Localizations
      • Current Localization
      • Localized Values
      • CLI Commands (LocaleBundle)
    • LoggerBundle
    • MessageQueueBundle
      • Commands
    • MigrationBundle
      • Commands
    • MicrosoftSyncBundle
    • NavigationBundle
      • Commands
    • NoteBundle
    • NotificationBundle
    • OAuth2ServerBundle
    • OrganizationBundle
    • PlatformBundle
      • Commands
    • QueryDesignerBundle
      • Query Designer Configuration
      • Condition Builder Component
    • RedisConfigBundle
      • Configure Redis Servers
      • Configure Application to Use Redis
    • ReportBundle
    • ScopeBundle
    • SearchBundle
      • ORM Search Engine
      • Search Relevance Weight
      • DateTimeFormatter
    • SecurityBundle
    • SegmentBundle
    • SidebarBundle
    • SyncBundle
      • Configuration
      • Client
      • Topics and Handlers
      • Authentication
      • Content Outdating
      • Origin Checking
      • Mediator Handlers
    • TagBundle
      • TagsEditorView
      • TagsView
    • TestFrameworkBundle
      • Additional Doctrine Events
    • ThemeBundle
    • TranslationBundle
      • Commands
    • TwigInspectorBundle
    • UIBundle
      • 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
    • WindowsBundle
    • WorkflowBundle
      • Commands
    • DraftBundle
      • How to Use Drafts
      • How to Use Draft ACL
      • How to Use the Draft Filter
      • How to Resolve Draft Conflicts
      • How to Use a Draft Extension
    • CatalogBundle
    • CheckoutBundle
    • CMSBundle
      • Content Widgets
      • WYSIWYG Field
        • How to Add WYSIWYG Field
        • How to Display a WYSIWYG Field
        • How to Change Textarea Field to WYSIWYG Field
        • WYSIWYG Field Validation
      • Content Blocks
      • Create Editor Components
    • ConsentBundle
      • Add the Customer Consents Field to a Form (Example)
      • Add the Agreements Step to a Custom Checkout Based on the Default Checkout Workflow (Example)
      • Add the Agreements Section to a Custom Checkout Based on the Single Page Checkout Workflow (Example)
    • CustomerBundle
    • FrontendBundle
      • Frontend Sessions and Debug Routes
      • Frontend Access
      • Set Up Mass Action in Datagrid
      • Sticky Panel View
      • Dom Relocation Global View
    • InventoryBundle
    • OrderBundle
      • Previously Purchased Products
    • PayPalBundle
    • PromotionBundle
    • PricingBundle
      • Configure Price List Sharding
      • Optimize Website Indexation and Price Recalculation
      • Combined Price List
      • Price Storage
      • Pricing Strategy
      • Commands
    • ProductBundle
      • Product Actions
      • Product Attributes
      • Product Unit Formatting
      • Product Variant Search
      • Related Items
      • Externally Stored Product Images
      • Product Customization Using Layouts
        • Customize Product View Page
        • Customize Product List Page
        • Customize Product Lists
        • Customize Products SKU Validation
    • RedirectBundle
    • SEOBundle
      • Sitemap
      • SEO Meta Fields
    • TaxBundle
    • WebCatalogBundle
    • WebsiteElasticSearchBundle
      • Website ElasticSearch Search Engine
      • Website ElasticSearch Configuration
      • Attributes Boost
      • Request Builders
      • Upgrade Website Index to Elasticsearch >=7.7, <8.0
      • Synonym Management
    • WebsiteSearchBundle
      • Website Search VS Regular Search
      • Website Search Configuration
      • Search Index Structure
      • Console Commands
      • Perform Search
      • Indexation Process
      • Reindexation During Platform Update
      • ORM Search Engine
      • Search Relevance Weight
      • Testing
    • ActivityContactBundle
    • AnalyticsBundle
    • ChannelBundle
    • SalesBundle
    • ApruveBundle
    • AuthorizeNetBundle
    • DotmailerBundle
    • DPDBundle
    • GoogleTagManagerBundle
    • InfinitePayBundle
    • MailchimpBundle
    • MakerBundle
    • PaypalExpressBundle
    • StripeBundle
  • 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

The interface Oro\Bundle\ProductBundle\RelatedItem\RelatedItemConfigProviderInterface represents the configuration for Related Items.

Example:

You can find example in Oro\Bundle\ProductBundle\RelatedItem\RelatedProduct\RelatedProductsConfigProvider.

Here is the quick overview of its usage:

isEnabled()

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

Returns information on whether the Related Items functionality is enabled.

getLimit()

$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()

$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 Finder 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\FinderDatabaseStrategy 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\FinderStrategyInterface, overload or decorate its definition: “oro_product.related_products.strategy”, and provide the implementation of the find method:

/**
 * @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

The assigner strategy (Oro\Bundle\ProductBundle\RelatedItem\AssignerStrategyInterface) provides a way to store the relation between the product and its related item. An example of the implementation can be found in Oro\Bundle\ProductBundle\RelatedItem\RelatedProduct\AssignerDatabaseStrategy.

It defines two methods:

  1. addRelations()

    /**
     * @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()

    /**
     * @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
  • OroMarketplace
  • OroCRM
  • OroPlatform
  • Partners
  • Services
  • Events
  • Twitter
  • Terms & conditions
  • Privacy policy
  • Contributor license agreement

@2021 Oro, Inc. All Rights Reserved.

Back to top