From 16bddbfc44df199f488c1a2701275fd8a65df2fa Mon Sep 17 00:00:00 2001 From: Tickles Date: Mon, 13 Nov 2017 12:28:21 +0100 Subject: [PATCH 1/2] Dynamically get all available ratings Get all available ratings and iterate over them and their options to build the rating_options array, instead of hardcoding. This ensures custom ratingsget faked data too. --- .../community/Ovs/Magefaker/Model/Faker.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/code/community/Ovs/Magefaker/Model/Faker.php b/app/code/community/Ovs/Magefaker/Model/Faker.php index f6f0ea6..a5081a0 100644 --- a/app/code/community/Ovs/Magefaker/Model/Faker.php +++ b/app/code/community/Ovs/Magefaker/Model/Faker.php @@ -429,12 +429,20 @@ protected function _addProductReviews($productId) $faker->addProvider(new Faker\Provider\Lorem($faker)); $reviewCount = mt_rand(0, 10); - - $rating_options = [ - 1 => [1, 2, 3, 4, 5], - 2 => [6, 7, 8, 9, 10], - 3 => [11, 12, 13, 14, 15], - ]; + + /** + * Get collection of reviews instead of hardcoding the default magento ones, + * this way we add ratings for custom added ones too. + */ + + $ratings = Mage::getModel('rating/rating')->getCollection(); + $rating_options = []; + foreach ($ratings as $rating) { + $options = $rating->getOptions(); + foreach ($options as $option) { + $rating_options[$rating->getData('rating_id')][] = $option->getData('option_id'); + } + } for ($y = 0; $y < $reviewCount; $y++) { $review = Mage::getModel('review/review'); From e30ac26b9d4c92c94f1c3ecd0cd6040fe81c3275 Mon Sep 17 00:00:00 2001 From: Tickles Bv Date: Mon, 13 Nov 2017 14:34:09 +0100 Subject: [PATCH 2/2] Change code according to required style & format --- app/code/community/Ovs/Magefaker/Model/Faker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Ovs/Magefaker/Model/Faker.php b/app/code/community/Ovs/Magefaker/Model/Faker.php index a5081a0..b8ee7e8 100644 --- a/app/code/community/Ovs/Magefaker/Model/Faker.php +++ b/app/code/community/Ovs/Magefaker/Model/Faker.php @@ -435,7 +435,7 @@ protected function _addProductReviews($productId) * this way we add ratings for custom added ones too. */ - $ratings = Mage::getModel('rating/rating')->getCollection(); + $ratings = Mage::getModel('rating/rating')->getCollection(); $rating_options = []; foreach ($ratings as $rating) { $options = $rating->getOptions();