install.xml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <modification>
  3. <name>Reverb Integration</name>
  4. <code>reverb</code>
  5. <version>1.0.0</version>
  6. <author>Reverb OpenCart</author>
  7. <link>https://reverb.com/au/page/integrations</link>
  8. <!--
  9. ========================================================================
  10. FILE 1: admin/controller/catalog/product.php
  11. Inject Reverb data loading before the view is rendered,
  12. and Reverb data saving after addProduct / editProduct calls.
  13. ========================================================================
  14. -->
  15. <file path="admin/controller/catalog/product.php">
  16. <!--
  17. Load per-product Reverb data into $data[] so the Twig template
  18. can render the Reverb tab. Targets the final setOutput() call in
  19. the shared getForm() method, which is used by both add() and edit().
  20. -->
  21. <operation>
  22. <search><![CDATA[$this->response->setOutput($this->load->view('catalog/product', $data));]]></search>
  23. <add position="before"><![CDATA[
  24. // Reverb Integration: load per-product Reverb data
  25. $this->load->model('extension/module/reverb');
  26. $reverb_product_id = isset($this->request->get['product_id']) ? (int)$this->request->get['product_id'] : 0;
  27. $reverb_row = $this->model_extension_module_reverb->getProductMap($reverb_product_id);
  28. $data['reverb_sync_enabled'] = $reverb_row ? (int)$reverb_row['sync_enabled'] : 0;
  29. $data['reverb_condition_uuid'] = $reverb_row ? $reverb_row['condition_uuid'] : '';
  30. $data['reverb_category_uuid'] = $reverb_row ? $reverb_row['reverb_category_uuid'] : '';
  31. $data['reverb_listing_id'] = $reverb_row ? $reverb_row['reverb_listing_id'] : '';
  32. $data['reverb_conditions'] = $this->model_extension_module_reverb->getListingConditions();
  33. $data['reverb_oc_category_mappings'] = $this->model_extension_module_reverb->getCategoryMappings();
  34. $data['reverb_categories'] = $this->model_extension_module_reverb->getReverbCategories();
  35. ]]></add>
  36. </operation>
  37. <!--
  38. Save Reverb data after editProduct() is called.
  39. -->
  40. <operation>
  41. <search><![CDATA[$this->model_catalog_product->editProduct($this->request->get['product_id'], $this->request->post);]]></search>
  42. <add position="after"><![CDATA[
  43. // Reverb Integration: save per-product Reverb data on edit
  44. if (isset($this->request->post['reverb_sync_enabled']) || isset($this->request->post['reverb_condition_uuid'])) {
  45. $this->load->model('extension/module/reverb');
  46. $this->model_extension_module_reverb->saveProductMap((int)$this->request->get['product_id'], [
  47. 'sync_enabled' => isset($this->request->post['reverb_sync_enabled']) ? 1 : 0,
  48. 'condition_uuid' => $this->request->post['reverb_condition_uuid'] ?? '',
  49. 'reverb_category_uuid' => $this->request->post['reverb_category_uuid'] ?? '',
  50. ]);
  51. }
  52. ]]></add>
  53. </operation>
  54. <!--
  55. Save Reverb data after addProduct() is called.
  56. -->
  57. <operation>
  58. <search><![CDATA[$product_id = $this->model_catalog_product->addProduct($this->request->post);]]></search>
  59. <add position="after"><![CDATA[
  60. // Reverb Integration: save per-product Reverb data on add
  61. if (isset($this->request->post['reverb_sync_enabled']) || isset($this->request->post['reverb_condition_uuid'])) {
  62. $this->load->model('extension/module/reverb');
  63. $this->model_extension_module_reverb->saveProductMap((int)$product_id, [
  64. 'sync_enabled' => isset($this->request->post['reverb_sync_enabled']) ? 1 : 0,
  65. 'condition_uuid' => $this->request->post['reverb_condition_uuid'] ?? '',
  66. 'reverb_category_uuid' => $this->request->post['reverb_category_uuid'] ?? '',
  67. ]);
  68. }
  69. ]]></add>
  70. </operation>
  71. </file>
  72. <!--
  73. ========================================================================
  74. FILE 2: admin/view/template/catalog/product.twig
  75. Add a "Reverb" tab to the product edit page.
  76. ========================================================================
  77. -->
  78. <file path="admin/view/template/catalog/product.twig">
  79. <!-- Add tab navigation item after the Design tab -->
  80. <operation>
  81. <search><![CDATA[<li><a href="#tab-design" data-toggle="tab">{{ tab_design }}</a></li>]]></search>
  82. <add position="after"><![CDATA[
  83. <li><a href="#tab-reverb" data-toggle="tab">Reverb</a></li>
  84. ]]></add>
  85. </operation>
  86. <!--
  87. Inject the Reverb tab pane. We include the dedicated template which
  88. has access to all $data variables (conditions, category mappings, etc.)
  89. loaded above by the PHP patch.
  90. -->
  91. <operation>
  92. <search><![CDATA[<div class="tab-pane" id="tab-design">]]></search>
  93. <add position="before"><![CDATA[
  94. {% include 'extension/module/reverb_product.twig' %}
  95. ]]></add>
  96. </operation>
  97. </file>
  98. </modification>