多嚿魚教室

Opencart優化技巧

In Opencart Admin panel, this is an Autocomplete function for entry of product attributes. When user types in something into the text field of product attribute, a word box of defined product attributes will appear below the field to let user click that wanted to save the typing time.

However, if the user does not click the word box and type a complete word by oneself, the Opencart system will not save the product attribute data the user types. In fact, the Autocomplete function wanted to prevent user inputting undefined product attributes. In other words, the system does not record what the user types but just detects which item the user clicks in the word box. The Autocomplete function is user-unfriendly, especially there are many product attributes defined.

To simplify the entry of product attributes, I have programmed a vQmod plug-in to change the text field into drop-down list so that the user does not need to type anything.

If vQmod have been installed in your Opencart system,
click the below fish and save the XML script into the directory [vqmod/xml].


<p>
&#60;!--<br />
Make sure that you have properly installed Opencart vQmod.<br />
Copy this page of script.<br />
Save as a .xml file of utf-8 encoding without BOM into the directory [vqmod/xml].<br />
Name the file as you like.<br />
--&gt;</p>
<pre contenteditable="true">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;modification&gt;
 &lt;id&gt;Display attribute choices of products in drop-down list&lt;/id&gt;
 &lt;version&gt;1.1.0&lt;/version&gt;
 &lt;author&gt;Flexidigi Solution Ltd.&lt;/author&gt;
 &lt;file name=&quot;admin/model/catalog/product.php&quot;&gt;
  &lt;operation&gt;
   &lt;search position=&quot;after&quot;&gt;&lt;![CDATA[class ModelCatalogProduct extends Model {]]&gt;&lt;/search&gt;
   &lt;add&gt;&lt;![CDATA[
 public function get_all_attribute_names() {
  $query = $this-&gt;db-&gt;query(&quot;SELECT attribute_group_id, attribute_id , name FROM &quot; . DB_PREFIX . &quot;attribute_description NATURAL JOIN &quot; . DB_PREFIX . &quot;attribute WHERE language_id = '&quot; . (int)$this-&gt;config-&gt;get('config_language_id') . &quot;' order by attribute_group_id DESC&quot;);
  
  return $query-&gt;rows;
 }
 public function get_all_attribute_group_names() {
  $query = $this-&gt;db-&gt;query(&quot;SELECT attribute_group_id , name FROM &quot; . DB_PREFIX . &quot;attribute_group_description WHERE language_id = '&quot; . (int)$this-&gt;config-&gt;get('config_language_id') . &quot;' order by attribute_group_id DESC&quot;);
  
  return $query-&gt;rows;
 }  
   ]]&gt;&lt;/add&gt;
  &lt;/operation&gt;
 &lt;/file&gt;
 &lt;file name=&quot;admin/controller/catalog/product.php&quot;&gt;
  &lt;operation&gt;
   &lt;search position=&quot;after&quot;&gt;&lt;![CDATA[private function getForm() {]]&gt;&lt;/search&gt;
   &lt;add&gt;&lt;![CDATA[
     $this-&gt;data['attribute_names'] = array();
  $results = $this-&gt;model_catalog_product-&gt;get_all_attribute_names();
  foreach ($results as $result) {
   $this-&gt;data['attribute_names'][] = array(
    'name' =&gt; $result['name'],
    'attribute_id' =&gt; $result['attribute_id'],
    'attribute_group_id' =&gt; $result['attribute_group_id']);
  }
  $this-&gt;data['attribute_group_names'] = array();
  $results = $this-&gt;model_catalog_product-&gt;get_all_attribute_group_names();
  foreach ($results as $result) {
   $this-&gt;data['attribute_group_names'][] = array(
    'name' =&gt; $result['name'],
    'attribute_group_id' =&gt; $result['attribute_group_id']);
  }
   ]]&gt;&lt;/add&gt;
  &lt;/operation&gt;
 &lt;/file&gt;
 &lt;file name=&quot;admin/view/template/catalog/product_form.tpl&quot;&gt;
 &lt;!-- Show all existing Product attributes --&gt;
  &lt;operation&gt;
   &lt;search position=&quot;before&quot; offset=&quot;1&quot;&gt;&lt;![CDATA[&lt;div id=&quot;tab-option&quot;&gt;]]&gt;&lt;/search&gt;
   &lt;add&gt;&lt;![CDATA[
   &lt;aside&gt;
   &lt;header style=&quot;margin-right: 3em;float:left;font-size:1.5em&quot;&gt;&lt;?php echo $entry_attribute; ?&gt;&lt;/header&gt;
            &lt;?php foreach ($attribute_group_names as $all_attribute_group){ ?&gt;
            &lt;details style=&quot;border:#6FF solid thin; margin-right: 3em; padding:1em;float:left;&quot;&gt;
            &lt;summary style=&quot;text-decoration:underline;&quot;&gt;&lt;?php print($all_attribute_group['name']); ?&gt;&lt;/summary&gt;
        &lt;ul style=&quot;list-style-type:none;&quot; title=&quot;&lt;?php echo $all_attribute_group['name']; ?&gt;&quot;&gt;
        &lt;?php foreach ($attribute_names as $all_attribute){ 
   if($all_attribute['attribute_group_id']==$all_attribute_group['attribute_group_id']) { ?&gt;
         &lt;li&gt;&lt;?php print($all_attribute['name']); ?&gt;&lt;/li&gt;
        &lt;?php } } ?&gt;
        &lt;/ul&gt;
        &lt;/details&gt;
        &lt;?php } ?&gt;
        &lt;/aside&gt;
   ]]&gt;&lt;/add&gt;
  &lt;/operation&gt;
  &lt;operation&gt;
   &lt;search position=&quot;replace&quot;&gt;&lt;![CDATA[&lt;input type=&quot;text&quot; name=&quot;product_attribute[' + attribute_row + '][name]&quot;]]&gt;&lt;/search&gt;
   &lt;add&gt;&lt;![CDATA[';
   html += '&lt;select title=&quot;Product attributes&quot; name=&quot;product_attribute[' + attribute_row + '][name]&quot; onchange=&quot;document.getElementsByName(\'product_attribute[' + attribute_row + '][attribute_id]\')[0].value=this.options[this.selectedIndex].value;&quot;&gt;';
   html += '&lt;option value=&quot;&quot; selected=&quot;selected&quot;&gt;&lt;?php echo $text_select; ?&gt;&lt;/option&gt;';
  &lt;?php foreach ($attribute_group_names as $all_attribute_group){ ?&gt;
  html += '&lt;optgroup label=&quot;&lt;?php echo $all_attribute_group['name']; ?&gt;&quot;&gt;';
  &lt;?php foreach ($attribute_names as $all_attribute){ 
   if($all_attribute['attribute_group_id']==$all_attribute_group['attribute_group_id']) { ?&gt;
   html += '&lt;option value=&quot;&lt;?php echo $all_attribute['attribute_id']; ?&gt;&quot;&gt;&lt;?php print($all_attribute['name']); ?&gt;&lt;/option&gt;';
  &lt;?php } } ?&gt;
  html += '&lt;/optgroup&gt;';
  &lt;?php } ?&gt;
 html += '    &lt;/select&gt;';
   html += '&lt;input style=&quot;visibility:hidden&quot; list=&quot;attribute_list&quot; type=&quot;text&quot; name=&quot;product_attribute[' + attribute_row + '][name]&quot;]]&gt;&lt;/add&gt;
  &lt;/operation&gt;
 &lt;/file&gt;
&lt;/modification&gt;
</pre>
唔識英文?
自己查字典啦!

2 comments:

Intersted in this vQmod, please send it to me at thatsashok@gmail.com.

The link above is not working.

Thanks in advance.

Ashok.

Could you kindly please send it to dotenaebyin@gmail.com ?

I would love you forever. :D

Post a Comment