/   /   /  OroCommerce B2B For Developers : Some product snippets

Note:

For more extensions and themes visit our store

OroCommerce B2B For Developers : Some product snippets


Load Product By id or by sku:

  1.  
  2. use  Oro\Bundle\ProductBundle\Entity\Product;
  3. $doctrineHelper = $this->container->get('oro_entity.doctrine_helper');
  4. $productRepository = $doctrineHelper->getEntityRepositoryForClass(Product::class);
  5. $productLoadedById = $productRepository->find(10);
  6. $productLoadedBySku = $productRepository->findOneBySku(‘somesku’);

Load products by Ids:

  1.  
  2. $productsLoadedByIds = $productRepository->getProductsByIds([2,4,5]);

Get Upsell Products:

  1.  
  2. use  Oro\Bundle\ProductBundle\Entity\RelatedItem\UpsellProduct;
  3. $upsellProductRepository  = $doctrineHelper->getEntityRepositoryForClass(UpsellProduct::class);
  4. $productId = 10;
  5. $limit = 8;
  6. $upsellProducts = $upsellProductRepository->findUpsell($id, $limit);

Get Related Products:

  1.  
  2. use  Oro\Bundle\ProductBundle\Entity\RelatedItem\RelatedProduct;
  3. $relatedProductRepository  = $doctrineHelper->getEntityRepositoryForClass(RelatedProduct::class);
  4. $productId = 10;
  5. $limit = 8;
  6. $bidirectional = true;
  7. $upsellProducts = $relatedProductRepository ->findRelated($id, true, $limit);

Test Products is newArrival or Featured:

  1.  
  2. $isNew = $product->isNewArrival();
  3. $isFeaturesd = $product->getFeatured();

 

Twig Snippets: 


Get Product Images by type:

  1.  
  2. {% import 'OroProductBundle::image_macros.html.twig' as Image %} 
  3. {% for productImage in product.imagesByType('additional') %}
  4.           <img src="{{ Image.url(productImage.image, 'product_small') }}" />
  5. {% endfor %}

imagesByType('additional') : you can use as parameters main , additional , listing
Image.url(productImage.image, 'product_small') : you can filter which one you size you wanna load 
     'product_large' , 'product_small' , 'product_original' , 'product_gallery_main'

 
Get first product image by type :

  1.  
  2. {% set productImage = product.imagesByType('listing').first.image|default(null) %}
  3. {% set productImageUrl = Image.url(productImage, 'product_small') %}

Get All Product page URL:

  1.  
  2. {% set product_url = path('oro_product_frontend_product_index') %}

Get Product view URL:

  1.  
  2. {% set product_url = path('oro_product_frontend_product_view', {id: product.id}) %}

Get Related Products Ids:

  1.  
  2. {% set relatedItemsIds = get_related_products_ids(product) %}

get UpSell Products Ids:

  1.  
  2. {% set upsellItemsIds = get_upsell_products_ids(product) %}

Comments

Related Posts

make your store more efficient

Solving problems. With open source technology. Professional results. That’s what makes Ibnab your best choice

IBNAB is a company made of a group of professionals whose work is providing secure open source solutions. Our company strives for reaching magnificent results with each experience and provides professional open source solutions that cover every part of the business process.