PHP code example of tourze / product-recommend-bundle
1. Go to this page and download the library: Download tourze/product-recommend-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tourze / product-recommend-bundle example snippets
use ProductRecommendBundle\Entity\RecommendBlock;
use ProductRecommendBundle\Entity\RecommendElement;
// Create a recommendation block
$block = new RecommendBlock();
$block->setTitle('Featured Products');
$block->setSubtitle('Our top recommendations');
$block->setValid(true);
// Add products to the block
$element = new RecommendElement();
$element->setBlock($block);
$element->setSpuId('12345');
$element->setThumb('/images/product.jpg');
$element->setTextReason('Best seller this month');
$element->setValid(true);
$entityManager->persist($block);
$entityManager->persist($element);
$entityManager->flush();
use ProductRecommendBundle\Repository\RecommendBlockRepository;
use ProductRecommendBundle\Repository\RecommendElementRepository;
// Get repository
$blockRepo = $entityManager->getRepository(RecommendBlock::class);
$elementRepo = $entityManager->getRepository(RecommendElement::class);
// Find active blocks
$activeBlocks = $blockRepo->findBy(['valid' => true]);
// Find elements by block
$elements = $elementRepo->findBy(['block' => $block, 'valid' => true]);
use ProductRecommendBundle\Entity\RecommendElementTag;
// Create and assign tags
$tag = new RecommendElementTag();
$tag->setTitle('Hot Deal');
$tag->setValid(true);
$element->addRecommendElementTag($tag);
use ProductRecommendBundle\Entity\RelatedRecommend;
// Create product-to-product recommendations
$related = new RelatedRecommend();
$related->setVisitSpuId('12345');
$related->setScene('product_detail');
$related->setRecommendSpuId('67890');
$related->setTextReason('Customers who viewed this also liked');
$related->setScore(0.8);
$related->setValid(true);
bash
php bin/console doctrine:migrations:migrate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.