Load Product By id or by sku:
use Oro\Bundle\ProductBundle\Entity\Product; $doctrineHelper = $this->container->get('oro_entity.doctrine_helper'); $productRepository = $doctrineHelper->getEntityRepositoryForClass(Product::class); $productLoadedById = $productRepository->find(10); $productLoadedBySku = $productRepository->findOneBySku(‘somesku’);
Load products by Ids:
$productsLoadedByIds = $productRepository->getProductsByIds([2,4,5]);
Get Upsell Products:
use Oro\Bundle\ProductBundle\Entity\RelatedItem\UpsellProduct; $upsellProductRepository = $doctrineHelper->getEntityRepositoryForClass(UpsellProduct::class); $productId = 10; $limit = 8; $upsellProducts = $upsellProductRepository->findUpsell($id, $limit);
Get Related Products:
use Oro\Bundle\ProductBundle\Entity\RelatedItem\RelatedProduct; $relatedProductRepository = $doctrineHelper->getEntityRepositoryForClass(RelatedProduct::class); $productId = 10; $limit = 8; $bidirectional = true; $upsellProducts = $relatedProductRepository ->findRelated($id, true, $limit);
Test Products is newArrival or Featured:
$isNew = $product->isNewArrival(); $isFeaturesd = $product->getFeatured();
Twig Snippets:
Get Product Images by type:
{% import 'OroProductBundle::image_macros.html.twig' as Image %} {% for productImage in product.imagesByType('additional') %} <img src="{{ Image.url(productImage.image, 'product_small') }}" /> {% 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 :
{% set productImage = product.imagesByType('listing').first.image|default(null) %} {% set productImageUrl = Image.url(productImage, 'product_small') %}
Get All Product page URL:
{% set product_url = path('oro_product_frontend_product_index') %}
Get Product view URL:
{% set product_url = path('oro_product_frontend_product_view', {id: product.id}) %}
Get Related Products Ids:
{% set relatedItemsIds = get_related_products_ids(product) %}
get UpSell Products Ids:
{% set upsellItemsIds = get_upsell_products_ids(product) %}
Comments