Tuesday, May 9, 2017

Custom OpenCart 2.3.0.2 theme


I was looking to customize the default theme in OpenCart 2.3.0.2 and realized that I will probably need to do quite a bit of work given there was no immediate “help” related on the subject.
In essence it turned out to be a lot less painful than I thought.
Here is what I did. Assuming new theme name “mytheme” and title “My Theme”.
Make copies…
  1. To start with copy the default folder found in
    upload/catalog/view/theme/default
    to a new folder in the same directory. Name it “mytheme“.
  2. Then copy the theme_default.php file in
    upload/admin/controller/extension/theme
    and place it in same directory. Name it “mytheme.php“.
    + Rename the class to (line 2):
    ControllerExtensionThemeMyTheme
    + Replace all “theme_default” text to “mytheme“. Yes there are a lot (197).
  3. Copy the theme_default.tpl in
    upload/admin/view/template/extension/theme
    and place it in the same directory. Name it “mytheme.tpl“.
    + Replace all “theme_default” text to “mytheme“. (48)
  4. Copy theme_default.php in
    upload/admin/language/en-gb/extension/theme
    and place it in the same directory. Name it “mytheme.php“.
    + Set the new theme’s title in heading_title (line 3) to “My Theme”.
  5. Finally for the thumnail image to show correctly in store settings rename default.png to mytheme.png in
    upload/catalog/view/theme/mytheme/image
Now go into your Administration > Extensions > Extensions and select Themes in “Choose the extension type”. You should be seeing your new theme. Install it with the green (+) button and edit it to enable it. Also ensure you set the correct theme directory whilst editing the theme!
Then in System > Settings edit your store to use your new theme.
That should do it. You can now go ahead and start chopping and changing the default theme.

Monday, November 7, 2016

PHP: Replace space in front of capitals in a string (Regex)

I have a number of strings which contain words which are bunched together and I need to seperate them up.

For example ThisWasCool - This Was Cool MyHomeIsHere - My Home Is Here

$String = 'TheCambodia';
$Words = preg_replace('/(?<!\ )[A-Z]/', ' $0', $String);
echo $Words;


Output: The Cambodia

Wednesday, October 26, 2016

How to display image from "image selection" field in transformation

You can use following sample code:





<img src="<%# GetDocumentUrl("Image", "") %>" />