Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class msOptionsPriceMsOnGetProductPrice extends msOptionsPricePlugin
  5. {
  6. public function run()
  7. {
  8. if ($this->modx->context->key == 'mgr') {
  9. return;
  10. }
  11.  
  12. /** @var msProduct $product */
  13. $product = $this->modx->getOption('product', $this->scriptProperties);
  14. if (
  15. !$product
  16. OR
  17. !($product instanceof xPDOObject)
  18. ) {
  19. return;
  20. }
  21.  
  22. $rid = $product->get('id');
  23. $data = $this->modx->getOption('data', $this->scriptProperties, array(), true);
  24. $returned = (array)$this->modx->getPlaceholder('_returned_price');
  25. $options = (array)$this->modx->getOption('msoptionsprice_options', $data, array(), true);
  26. $reload = (bool)$this->modx->getOption('msoptionsprice_reload', $data, false, true);
  27.  
  28. if (
  29. empty($options)
  30. AND
  31. (isset($returned['id']) AND $returned['id'] == $rid)
  32. ) {
  33. $options = (array)$this->modx->getOption('msoptionsprice_options', $returned, array(), true);
  34. } else {
  35. if (empty($options)) {
  36. $options = (array)$this->modx->getOption('options', $_REQUEST, array(), true);
  37. }
  38. }
  39.  
  40. if (
  41. !$price = $this->modx->getOption('price', $returned)
  42. OR
  43. !isset($returned['id'])
  44. OR
  45. $returned['id'] != $rid
  46. OR
  47. $reload
  48. ) {
  49. $price = $this->modx->getOption('price', $this->scriptProperties, 0, true);
  50. }
  51.  
  52.  
  53. $queryOptions = $options;
  54. $modifications = array();
  55. $excludeIds = $excludeType = array(0);
  56.  
  57. $cost = $price;
  58.  
  59. while (
  60. $modification = $this->msoptionsprice->getModificationByOptions($rid, $queryOptions, null, $excludeIds,
  61. $excludeType)
  62. ) {
  63. $modifications[] = $modification;
  64. $excludeIds[] = $modification['id'];
  65. $cost = $this->msoptionsprice->getCostByModification($rid, $price, $modification);
  66. if ($cost !== false) {
  67. $price = $cost;
  68. }
  69. }
  70.  
  71. if (empty($modifications) AND $modification = $this->msoptionsprice->getModificationById(0, $rid, $options)) {
  72. $modifications[] = $modification;
  73. $cost = $this->msoptionsprice->getCostByModification($rid, $price, $modification);
  74.  
  75. if (isset($modification['options'])) {
  76. $options = (array)$modification['options'];
  77. }
  78. }
  79.  
  80. /*******************************************/
  81. $response = $this->msoptionsprice->miniShop2->invokeEvent('msopOnGetFullCost', array(
  82. 'product' => $product,
  83. 'rid' => $rid,
  84. 'cost' => $cost,
  85. 'options' => $options,
  86. 'modifications' => $modifications,
  87. ));
  88. if (!$response['success']) {
  89. return $response['message'];
  90. }
  91. $rid = $response['data']['rid'];
  92. $cost = $response['data']['cost'];
  93. $options = $response['data']['options'];
  94. /*******************************************/
  95.  
  96. $returned['id'] = $rid;
  97. $returned['msoptionsprice_options'] = $options;
  98. $this->modx->event->returnedValues['price'] = $returned['price'] = $cost;
  99. $this->modx->setPlaceholder('_returned_price', $returned);
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement