Difference between revisions of "Opencart duplicate module example"

From Wiki at Neela Nurseries
Jump to: navigation, search
m
m (^ To Create New Flat Shipping Rate and Geozones)
 
(17 intermediate revisions by the same user not shown)
Line 14: Line 14:
 
== Example Of Additional Flat Rate Shipping Modules ==
 
== Example Of Additional Flat Rate Shipping Modules ==
  
 +
{| class="wikitable"
 +
|-
 +
|
 +
column 1:<br />
 +
We annotate our `find` results so we can more readily compare<br /> what files we modified to realize new shipping methods:
 
<pre>
 
<pre>
 
$ find . -name '*flat*'
 
$ find . -name '*flat*'
 +
 +
1)
 +
./admin/controller/extension/shipping/flat_rate_to_europe.php
 +
./admin/controller/extension/shipping/flat_rate_to_canada.php
 +
./admin/controller/extension/shipping/flat.php
 +
 +
2)
 +
./admin/language/en-gb/extension/shipping/flat_rate_to_europe.php
 +
./admin/language/en-gb/extension/shipping/flat_rate_to_canada.php
 +
./admin/language/en-gb/extension/shipping/flat.php
 +
 +
3)
 
./admin/view/template/extension/shipping/flat_rate_to_europe.tpl
 
./admin/view/template/extension/shipping/flat_rate_to_europe.tpl
 
./admin/view/template/extension/shipping/flat.tpl
 
./admin/view/template/extension/shipping/flat.tpl
 
./admin/view/template/extension/shipping/flat_rate_to_canada.tpl
 
./admin/view/template/extension/shipping/flat_rate_to_canada.tpl
  
./admin/language/en-gb/extension/shipping/flat_rate_to_europe.php
+
4)
./admin/language/en-gb/extension/shipping/flat_rate_to_canada.php
+
 
./admin/language/en-gb/extension/shipping/flat.php
 
  
./admin/controller/extension/shipping/flat_rate_to_europe.php
 
./admin/controller/extension/shipping/flat_rate_to_canada.php
 
./admin/controller/extension/shipping/flat.php
 
  
./catalog/model/extension/shipping/flat_rate_to_europe.php
 
./catalog/model/extension/shipping/flat_rate_to_canada.php
 
./catalog/model/extension/shipping/flat.php
 
  
 +
5)
 
./catalog/language/en-gb/extension/shipping/flat_rate_to_europe.php
 
./catalog/language/en-gb/extension/shipping/flat_rate_to_europe.php
 
./catalog/language/en-gb/extension/shipping/flat_rate_to_canada.php
 
./catalog/language/en-gb/extension/shipping/flat_rate_to_canada.php
 
./catalog/language/en-gb/extension/shipping/flat.php
 
./catalog/language/en-gb/extension/shipping/flat.php
  
 +
6)
 +
./catalog/model/extension/shipping/flat_rate_to_europe.php
 +
./catalog/model/extension/shipping/flat_rate_to_canada.php
 +
./catalog/model/extension/shipping/flat.php
 +
 +
7)
 
$
 
$
 +
 +
 +
 +
</pre>
 +
 +
|
 +
column 2<br />
 +
<i> From https://forum.opencart.com/viewtopic.php?t=6696:<br />
 +
There are generally 6-8 files that need to be cloned for each
 +
module, and they follow a similar structure:
 +
</i>
 +
<pre>
 +
1. admin/controller/payment/cod.php
 +
 +
 +
 +
 +
2. admin/language/english/payment/cod.php
 +
 +
 +
 +
 +
3. admin/view/template/payment/cod.tpl
 +
 +
 +
 +
 +
4. catalog/controller/payment/cod.php
 +
 +
 +
 +
 +
5. catalog/language/english/payment/cod.php
 +
 +
 +
 +
 +
6. catalog/model/payment/cod.php
 +
 +
 +
 +
 +
7. catalog/view/theme/default/template/payment/cod.tpl
 +
 +
 +
 +
 +
 +
 +
 +
 +
</pre>
 +
|}
 +
 +
In the path of the third group of files, path admin/controller/extension/shipping, one must change a PHP class name near the top of the duplicated file, in a manner similar to:
 +
 +
<pre>
 +
<?php
 +
// class ControllerExtensionShippingFlat extends Controller {
 +
class ControllerExtensionShippingAndPhytoEurope extends Controller {
 +
 
</pre>
 
</pre>
  
 +
Similar editing needed in files in group four just above . . .
  
 
<!-- comment -->
 
<!-- comment -->
Line 87: Line 166:
  
  
 +
<!-- comment -->
 +
 +
== [[#top|^]] To Create New Flat Shipping Rate and Geozones ==
 +
 +
2021-10-19 Tuesday -
 +
To create shipping rates to one or more new geographies . . .
 +
{|
 +
|-
 +
||
 +
<pre>
 +
opencart-2p3p0p2]$ find . -name '*denmark*'
 +
./admin/view/template/extension/shipping/postage_in_denmark.tpl
 +
./admin/view/template/extension/shipping/postage_outside_denmark.tpl
 +
 +
./admin/language/en-gb/extension/shipping/postage_in_denmark.php
 +
./admin/language/en-gb/extension/shipping/postage_outside_denmark.php
 +
 +
./admin/controller/extension/shipping/postage_in_denmark.php
 +
./admin/controller/extension/shipping/postage_outside_denmark.php
 +
 +
./catalog/model/extension/shipping/postage_in_denmark.php
 +
./catalog/model/extension/shipping/postage_outside_denmark.php
 +
 +
./catalog/language/en-gb/extension/shipping/postage_in_denmark.php
 +
./catalog/language/en-gb/extension/shipping/postage_outside_denmark.php
 +
</pre>
 +
|
 +
Column 2 content
 +
|}
 +
 +
Steps to create new shipping methods (options) in Opencart 3.0.3.7:
 +
 +
(1)
 +
  $ opencart-3p0p3p7/admin/view/template/extension/shipping]$ cp -pv flat.twig postage_in_denmark.twig
 +
  `flat.twig' -> `postage_in_denmark.twig'
 +
 +
(2)
 +
  In `vi` editor sessions of dot php files in above list, substitute like the following (enter your choice of replacement for 'flat'):
 +
  :1,$s/flat/postage_in_denmark/g
  
 
<!-- comment -->
 
<!-- comment -->

Latest revision as of 04:32, 20 October 2021


2018-07-01 Sunday: how to duplicate handling fee module in Opencart


Overview

Want to add a fee similar to Opencart's default handling fee for ship-able orders. Free but technical way to do this is to duplicate files which implement the handling fee, making changes in them so they appear as a new Opencart module in Opencart's Extensions -> Order Totals admin page.


Example Of Additional Flat Rate Shipping Modules

column 1:
We annotate our `find` results so we can more readily compare
what files we modified to realize new shipping methods:

$ find . -name '*flat*'

1)
./admin/controller/extension/shipping/flat_rate_to_europe.php
./admin/controller/extension/shipping/flat_rate_to_canada.php
./admin/controller/extension/shipping/flat.php

2)
./admin/language/en-gb/extension/shipping/flat_rate_to_europe.php
./admin/language/en-gb/extension/shipping/flat_rate_to_canada.php
./admin/language/en-gb/extension/shipping/flat.php

3)
./admin/view/template/extension/shipping/flat_rate_to_europe.tpl
./admin/view/template/extension/shipping/flat.tpl
./admin/view/template/extension/shipping/flat_rate_to_canada.tpl

4)




5)
./catalog/language/en-gb/extension/shipping/flat_rate_to_europe.php
./catalog/language/en-gb/extension/shipping/flat_rate_to_canada.php
./catalog/language/en-gb/extension/shipping/flat.php

6)
./catalog/model/extension/shipping/flat_rate_to_europe.php
./catalog/model/extension/shipping/flat_rate_to_canada.php
./catalog/model/extension/shipping/flat.php

7)
$



column 2
From https://forum.opencart.com/viewtopic.php?t=6696:
There are generally 6-8 files that need to be cloned for each module, and they follow a similar structure:

1. admin/controller/payment/cod.php




2. admin/language/english/payment/cod.php




3. admin/view/template/payment/cod.tpl




4. catalog/controller/payment/cod.php




5. catalog/language/english/payment/cod.php




6. catalog/model/payment/cod.php




7. catalog/view/theme/default/template/payment/cod.tpl








In the path of the third group of files, path admin/controller/extension/shipping, one must change a PHP class name near the top of the duplicated file, in a manner similar to:

<?php
// class ControllerExtensionShippingFlat extends Controller {
class ControllerExtensionShippingAndPhytoEurope extends Controller {

Similar editing needed in files in group four just above . . .


Locating Existing OC Module Files

Searching for handling fee related files in Opencart 2.3.0.2 root directory:

$ find . -name '*hand*'
./admin/view/template/extension/total/handling.tpl
./admin/language/en-gb/extension/total/handling.php
./admin/controller/extension/total/handling.php
./catalog/model/extension/total/handling.php
./catalog/language/en-gb/extension/total/handling.php

$

Adding a comment block top of newly duplicated and modified files:

// <!--
// 2018-07-01 - file duplicated from ./handling.tpl and modified by Ted,
// to support phytosanitation fee.  Duplicating Opencart modules in this manner
// explained at https://forum.opencart.com/viewtopic.php?t=6696
//
// Replacing 'Handling' and 'handling' with '[Pp]hytosanitation' . . .
// -->


Creating New Combined Shipping Plus Phyto Rates

Argh, taxes apply per geographic area, but also per product and so are multiplied by number of products in cart! 'Order Total' type fee like handling fee applies to all orders. We need a fee which applies once to the order, per geography . . .

<! --
2018-07-01 - This OC template file duplicated from ./flat.tpl by Ted,
search and replace performed in vim as follows:
:.,$s/flat/shipping_and_phyto_europe/g
See https://forum.opencart.com/viewtopic.php?t=6696 for OC module duplicating details.
-->


^ To Create New Flat Shipping Rate and Geozones

2021-10-19 Tuesday - To create shipping rates to one or more new geographies . . .

opencart-2p3p0p2]$ find . -name '*denmark*'
./admin/view/template/extension/shipping/postage_in_denmark.tpl
./admin/view/template/extension/shipping/postage_outside_denmark.tpl

./admin/language/en-gb/extension/shipping/postage_in_denmark.php
./admin/language/en-gb/extension/shipping/postage_outside_denmark.php

./admin/controller/extension/shipping/postage_in_denmark.php
./admin/controller/extension/shipping/postage_outside_denmark.php

./catalog/model/extension/shipping/postage_in_denmark.php
./catalog/model/extension/shipping/postage_outside_denmark.php

./catalog/language/en-gb/extension/shipping/postage_in_denmark.php
./catalog/language/en-gb/extension/shipping/postage_outside_denmark.php

Column 2 content

Steps to create new shipping methods (options) in Opencart 3.0.3.7:

(1)

 $ opencart-3p0p3p7/admin/view/template/extension/shipping]$ cp -pv flat.twig postage_in_denmark.twig
 `flat.twig' -> `postage_in_denmark.twig'

(2)

 In `vi` editor sessions of dot php files in above list, substitute like the following (enter your choice of replacement for 'flat'):
 :1,$s/flat/postage_in_denmark/g


References