Jelajahi Sumber

Fix OCMOD tab injection by anchoring on SEO tab and embedding content inline

The Design tab search string was not matching the target product.twig,
silently skipping the injection. Changed anchor to the SEO tab (always
present in OC3) and embedded the Reverb tab HTML directly in the OCMOD
XML to avoid Twig include path resolution issues.

Also replaced PHP 7.0+ short array syntax and ?? operators in injected
PHP with older-compatible equivalents for maximum server compatibility.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Benjamin Harris 2 minggu lalu
induk
melakukan
157de46254
1 mengubah file dengan 94 tambahan dan 43 penghapusan
  1. 94 43
      install.xml

+ 94 - 43
install.xml

@@ -2,7 +2,7 @@
 <modification>
     <name>Reverb Integration</name>
     <code>reverb</code>
-    <version>1.0.1</version>
+    <version>1.0.2</version>
     <author>Reverb OpenCart</author>
     <link>https://reverb.com/au/page/integrations</link>
 
@@ -15,60 +15,45 @@
     -->
     <file path="admin/controller/catalog/product.php">
 
-        <!--
-            Load per-product Reverb data into $data[] so the Twig template
-            can render the Reverb tab. Targets the final setOutput() call in
-            the shared getForm() method, which is used by both add() and edit().
-        -->
         <operation>
             <search><![CDATA[$this->response->setOutput($this->load->view('catalog/product', $data));]]></search>
             <add position="before"><![CDATA[
-                // Reverb Integration: load per-product Reverb data
                 $this->load->model('extension/module/reverb');
                 $reverb_product_id = isset($this->request->get['product_id']) ? (int)$this->request->get['product_id'] : 0;
                 $reverb_row = $this->model_extension_module_reverb->getProductMap($reverb_product_id);
-                $data['reverb_sync_enabled']         = $reverb_row ? (int)$reverb_row['sync_enabled']         : 0;
-                $data['reverb_condition_uuid']        = $reverb_row ? $reverb_row['condition_uuid']            : '';
-                $data['reverb_category_uuid']         = $reverb_row ? $reverb_row['reverb_category_uuid']      : '';
-                $data['reverb_listing_id']            = $reverb_row ? $reverb_row['reverb_listing_id']         : '';
-                $data['reverb_conditions']            = $this->model_extension_module_reverb->getListingConditions();
-                $data['reverb_oc_category_mappings']  = $this->model_extension_module_reverb->getCategoryMappings();
-                $data['reverb_categories']            = $this->model_extension_module_reverb->getReverbCategories();
+                $data['reverb_sync_enabled']   = $reverb_row ? (int)$reverb_row['sync_enabled']        : 0;
+                $data['reverb_condition_uuid']  = $reverb_row ? $reverb_row['condition_uuid']           : '';
+                $data['reverb_category_uuid']   = $reverb_row ? $reverb_row['reverb_category_uuid']     : '';
+                $data['reverb_listing_id']      = $reverb_row ? $reverb_row['reverb_listing_id']        : '';
+                $data['reverb_conditions']      = $this->model_extension_module_reverb->getListingConditions();
+                $data['reverb_categories']      = $this->model_extension_module_reverb->getReverbCategories();
             ]]></add>
         </operation>
 
-        <!--
-            Save Reverb data after editProduct() is called.
-        -->
         <operation>
             <search><![CDATA[$this->model_catalog_product->editProduct($this->request->get['product_id'], $this->request->post);]]></search>
             <add position="after"><![CDATA[
-                // Reverb Integration: save per-product Reverb data on edit
                 if (isset($this->request->post['reverb_sync_enabled']) || isset($this->request->post['reverb_condition_uuid'])) {
                     $this->load->model('extension/module/reverb');
-                    $this->model_extension_module_reverb->saveProductMap((int)$this->request->get['product_id'], [
+                    $this->model_extension_module_reverb->saveProductMap((int)$this->request->get['product_id'], array(
                         'sync_enabled'         => isset($this->request->post['reverb_sync_enabled']) ? 1 : 0,
-                        'condition_uuid'       => $this->request->post['reverb_condition_uuid']  ?? '',
-                        'reverb_category_uuid' => $this->request->post['reverb_category_uuid']  ?? '',
-                    ]);
+                        'condition_uuid'       => isset($this->request->post['reverb_condition_uuid'])  ? $this->request->post['reverb_condition_uuid']  : '',
+                        'reverb_category_uuid' => isset($this->request->post['reverb_category_uuid'])  ? $this->request->post['reverb_category_uuid']  : '',
+                    ));
                 }
             ]]></add>
         </operation>
 
-        <!--
-            Save Reverb data after addProduct() is called.
-        -->
         <operation>
             <search><![CDATA[$product_id = $this->model_catalog_product->addProduct($this->request->post);]]></search>
             <add position="after"><![CDATA[
-                // Reverb Integration: save per-product Reverb data on add
                 if (isset($this->request->post['reverb_sync_enabled']) || isset($this->request->post['reverb_condition_uuid'])) {
                     $this->load->model('extension/module/reverb');
-                    $this->model_extension_module_reverb->saveProductMap((int)$product_id, [
+                    $this->model_extension_module_reverb->saveProductMap((int)$product_id, array(
                         'sync_enabled'         => isset($this->request->post['reverb_sync_enabled']) ? 1 : 0,
-                        'condition_uuid'       => $this->request->post['reverb_condition_uuid']  ?? '',
-                        'reverb_category_uuid' => $this->request->post['reverb_category_uuid']  ?? '',
-                    ]);
+                        'condition_uuid'       => isset($this->request->post['reverb_condition_uuid'])  ? $this->request->post['reverb_condition_uuid']  : '',
+                        'reverb_category_uuid' => isset($this->request->post['reverb_category_uuid'])  ? $this->request->post['reverb_category_uuid']  : '',
+                    ));
                 }
             ]]></add>
         </operation>
@@ -79,28 +64,94 @@
         ========================================================================
         FILE 2: admin/view/template/catalog/product.twig
         Add a "Reverb" tab to the product edit page.
+        Anchored on the SEO tab (always present in OC3) rather than Design tab
+        to avoid mismatches with customised themes. Content embedded inline to
+        avoid Twig include path resolution issues.
         ========================================================================
     -->
     <file path="admin/view/template/catalog/product.twig">
 
-        <!-- Add tab navigation item after the Design tab -->
         <operation>
-            <search><![CDATA[<li><a href="#tab-design" data-toggle="tab">{{ tab_design }}</a></li>]]></search>
-            <add position="after"><![CDATA[
-                <li><a href="#tab-reverb" data-toggle="tab">Reverb</a></li>
-            ]]></add>
+            <search><![CDATA[<li><a href="#tab-seo" data-toggle="tab">{{ tab_seo }}</a></li>]]></search>
+            <add position="after"><![CDATA[<li><a href="#tab-reverb" data-toggle="tab">Reverb</a></li>]]></add>
         </operation>
 
-        <!--
-            Inject the Reverb tab pane. We include the dedicated template which
-            has access to all $data variables (conditions, category mappings, etc.)
-            loaded above by the PHP patch.
-        -->
         <operation>
-            <search><![CDATA[<div class="tab-pane" id="tab-design">]]></search>
+            <search><![CDATA[<div class="tab-pane" id="tab-seo">]]></search>
             <add position="before"><![CDATA[
-                {% include 'extension/module/reverb_product.twig' %}
-            ]]></add>
+<div class="tab-pane" id="tab-reverb">
+  <div class="panel panel-default" style="margin-top:15px;">
+    <div class="panel-body">
+
+      <div class="form-group">
+        <label class="col-sm-2 control-label">List on Reverb</label>
+        <div class="col-sm-10">
+          <input type="hidden" name="reverb_sync_enabled" value="0" />
+          <label class="checkbox-inline">
+            <input type="checkbox" name="reverb_sync_enabled" value="1"
+                   {% if reverb_sync_enabled %}checked="checked"{% endif %} />
+            Enable sync for this product
+          </label>
+          <p class="help-block">Enable to include this product in Reverb syncs. The product must also be in an allowed category (set in the Reverb module settings).</p>
+        </div>
+      </div>
+
+      <div class="form-group">
+        <label class="col-sm-2 control-label">Condition</label>
+        <div class="col-sm-4">
+          <select name="reverb_condition_uuid" class="form-control">
+            <option value="">-- Select Condition --</option>
+            {% for condition in reverb_conditions %}
+            <option value="{{ condition.uuid }}"
+              {% if reverb_condition_uuid == condition.uuid %}selected="selected"{% endif %}>
+              {{ condition.display_name }}
+            </option>
+            {% endfor %}
+          </select>
+          <p class="help-block">Required by Reverb. Describes the physical state of the item.</p>
+        </div>
+      </div>
+
+      <div class="form-group">
+        <label class="col-sm-2 control-label">Reverb Category</label>
+        <div class="col-sm-6">
+          <select name="reverb_category_uuid" class="form-control">
+            <option value="">-- Use category mapping default --</option>
+            {% for rc in reverb_categories %}
+            <option value="{{ rc.uuid }}"
+              {% if reverb_category_uuid == rc.uuid %}selected="selected"{% endif %}>
+              {{ rc.full_name|default(rc.name) }}
+            </option>
+            {% endfor %}
+          </select>
+          <p class="help-block">Leave blank to use the default mapping from the Reverb module settings.</p>
+        </div>
+      </div>
+
+      {% if reverb_listing_id %}
+      <div class="form-group">
+        <label class="col-sm-2 control-label">Reverb Listing</label>
+        <div class="col-sm-10">
+          <p class="form-control-static">
+            <a href="https://reverb.com/item/{{ reverb_listing_id }}" target="_blank" rel="noopener">
+              <i class="fa fa-external-link"></i> View on Reverb (ID: {{ reverb_listing_id }})
+            </a>
+          </p>
+        </div>
+      </div>
+      {% else %}
+      <div class="form-group">
+        <label class="col-sm-2 control-label">Reverb Listing</label>
+        <div class="col-sm-10">
+          <p class="form-control-static text-muted">Not yet synced to Reverb.</p>
+        </div>
+      </div>
+      {% endif %}
+
+    </div>
+  </div>
+</div>
+]]></add>
         </operation>
 
     </file>