reverb.ocmod.xml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. ]]></add>
  35. </operation>
  36. <!--
  37. Save Reverb data after editProduct() is called.
  38. -->
  39. <operation>
  40. <search><![CDATA[$this->model_catalog_product->editProduct($this->request->get['product_id'], $this->request->post);]]></search>
  41. <add position="after"><![CDATA[
  42. // Reverb Integration: save per-product Reverb data on edit
  43. if (isset($this->request->post['reverb_sync_enabled']) || isset($this->request->post['reverb_condition_uuid'])) {
  44. $this->load->model('extension/module/reverb');
  45. $this->model_extension_module_reverb->saveProductMap((int)$this->request->get['product_id'], [
  46. 'sync_enabled' => isset($this->request->post['reverb_sync_enabled']) ? 1 : 0,
  47. 'condition_uuid' => $this->request->post['reverb_condition_uuid'] ?? '',
  48. 'reverb_category_uuid' => $this->request->post['reverb_category_uuid'] ?? '',
  49. ]);
  50. }
  51. ]]></add>
  52. </operation>
  53. <!--
  54. Save Reverb data after addProduct() is called.
  55. -->
  56. <operation>
  57. <search><![CDATA[$product_id = $this->model_catalog_product->addProduct($this->request->post);]]></search>
  58. <add position="after"><![CDATA[
  59. // Reverb Integration: save per-product Reverb data on add
  60. if (isset($this->request->post['reverb_sync_enabled']) || isset($this->request->post['reverb_condition_uuid'])) {
  61. $this->load->model('extension/module/reverb');
  62. $this->model_extension_module_reverb->saveProductMap((int)$product_id, [
  63. 'sync_enabled' => isset($this->request->post['reverb_sync_enabled']) ? 1 : 0,
  64. 'condition_uuid' => $this->request->post['reverb_condition_uuid'] ?? '',
  65. 'reverb_category_uuid' => $this->request->post['reverb_category_uuid'] ?? '',
  66. ]);
  67. }
  68. ]]></add>
  69. </operation>
  70. </file>
  71. <!--
  72. ========================================================================
  73. FILE 2: admin/view/template/catalog/product.twig
  74. Add a "Reverb" tab to the product edit page.
  75. ========================================================================
  76. -->
  77. <file path="admin/view/template/catalog/product.twig">
  78. <!-- Add tab navigation item after the Design tab -->
  79. <operation>
  80. <search><![CDATA[<li><a href="#tab-design" data-toggle="tab">{{ tab_design }}</a></li>]]></search>
  81. <add position="after"><![CDATA[
  82. <li><a href="#tab-reverb" data-toggle="tab">Reverb</a></li>
  83. ]]></add>
  84. </operation>
  85. <!--
  86. Inject the Reverb tab pane. We include the dedicated template which
  87. has access to all $data variables (conditions, category mappings, etc.)
  88. loaded above by the PHP patch.
  89. -->
  90. <operation>
  91. <search><![CDATA[<div class="tab-pane" id="tab-design">]]></search>
  92. <add position="before"><![CDATA[
  93. {% include 'extension/module/reverb_product.twig' %}
  94. ]]></add>
  95. </operation>
  96. </file>
  97. </modification>