Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2. /**
  3. * Installation script for tvoe rating custom
  4. */
  5. $installer = $this;
  6. $installer->startSetup();
  7.  
  8. function addOptions($rating) {
  9. for ($i = 1; $i <= 5; $i++) {
  10. Mage::getModel('rating/rating_option')->setData(
  11. array(
  12. 'rating_id' =>$rating->getId(),
  13. 'code' => $i,
  14. 'value' => $i,
  15. 'position' => $i
  16. )
  17. )->save();
  18. }
  19. }
  20.  
  21. $ratingTvoe = array(
  22. 'rating_code' => 'tvoe_summary',
  23. 'entity_id' => 1,
  24. 'stores' => array(Mage::app()->getStore()->getId()),
  25. 'position' => 0
  26. );
  27.  
  28. // Create rating
  29. $rating = Mage::getModel('rating/rating')->getCollection()->addFieldToFilter('rating_code', 'tvoe')->getFirstItem();
  30.  
  31. if ($rating->getId()) {
  32. $rating->setRatingCode($ratingTvoe['rating_code']);
  33. $rating->setEntityId($ratingTvoe['entity_id']);
  34. $rating->setStores($ratingTvoe['stores']);
  35. $rating->setPosition(0);
  36.  
  37. if (!count($rating->getOptions())) {
  38. addOptions($rating);
  39. }
  40. } else {
  41.  
  42. $rating = Mage::getModel('rating/rating')->setData($ratingTvoe)->save();
  43. if (!count($rating->getOptions())) {
  44. addOptions($rating);
  45. }
  46. }
  47.  
  48. $installer->endSetup();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement