Last active
October 12, 2017 16:36
-
-
Save aamnah/d8b5d31a2ca464b8af09d32be19a99a0 to your computer and use it in GitHub Desktop.
Copy the default OpenCart theme, re-structure it, update links and make it ready to be published as an .ocmod.zip file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copy Default Theme | |
| # run this script from inside `catalog/view/theme/` | |
| # (the themes directory for OpenCart, i.e. where your 'default' theme folder resides) | |
| # run: bash catalog/view/theme/copyTheme.sh foo | |
| # TODO | |
| # [ ] add status/progress messages | |
| # [ ] add error handling, if the folder already exists etc. | |
| themeToCopy='default' # hard coded to copy the default theme | |
| newThemeName=$1 # 1st argument | |
| headerFile="${newThemeName}/template/common/header.tpl" | |
| siteFolder=`pwd` | |
| copyDefaultTheme() { | |
| # copy theme dir | |
| cp -r ${themeToCopy} ${newThemeName} # Theme Files | |
| cp ../javascript/common.js ../javascript/${newThemeName}.js # Default JS file | |
| cp ${newThemeName}/stylesheet/stylesheet.css ${newThemeName}/stylesheet/stylesheet.scss # Because i write my styles in Sass | |
| } | |
| updateHeaderLinks() { | |
| # update links in header file | |
| # CSS | |
| sed -i '' "s/theme\/default/theme\/${newThemeName}/" ${headerFile} # CSS link | |
| sed -i '' "s/javascript\/common.js/javascript\/${newThemeName}.js/" ${headerFile} # JS link | |
| } | |
| changeStructure() { | |
| # change the folder structure and make symlinks for easy distribution | |
| # this makes it easy to compress and upload the theme as an .ocmod.zip | |
| uploadDirectory="${newThemeName}/upload/catalog/view/theme/${newThemeName}" | |
| # create the upload/ fodler | |
| mkdir -p ${uploadDirectory} | |
| # move everything to the upload/ folder | |
| mv ${newThemeName}/image ${uploadDirectory}/ | |
| mv ${newThemeName}/stylesheet ${uploadDirectory}/ | |
| mv ${newThemeName}/template ${uploadDirectory}/ | |
| # create Symlinks so the folders now moved to uploads dir can | |
| # still be viewed in the new Theme's root folder | |
| # and served by the server | |
| ln -s ${siteFolder}/${uploadDirectory}/image ${newThemeName}/ | |
| ln -s ${siteFolder}/${uploadDirectory}/stylesheet ${newThemeName}/ | |
| ln -s ${siteFolder}/${uploadDirectory}/template ${newThemeName}/ | |
| } | |
| createFiles() { | |
| # create an install.xml (needed for publishing theme) | |
| touch ${newThemeName}/install.xml | |
| echo -e "<!-- This is your install.xml | |
| This needs to be included in your .ocmod.zip, even if it is empty. --> | |
| <modification> | |
| <name>${newThemeName}</name> | |
| <code>${newThemeName}</code> | |
| <description><![CDATA[Tweaks that make the theme work and are needed]]></description> | |
| <version>0.1</version> | |
| <author>Aamnah</author> | |
| <link>http://aamnah.com</link> | |
| </modification> | |
| " > ${newThemeName}/install.xml | |
| # cerate a README.md for the project | |
| touch ${newThemeName}/README.md | |
| echo -e "# ${newThemeName} | |
| This theme was copied from the ${themeToCopy} OpenCart theme. It has an uploads folder and an install.xml file ready to be compressed as an \`.ocmod.zip\` file and installed via _Extension Installer_ | |
| ### Stylesheet | |
| The links for the stylesheet has been updated in the \`header.tpl\` file to reflect the stylesheet of our new theme | |
| ### JavaScript | |
| The \`common.js\` file in \`catalog/view/javascript\` folder has been copied and renamed to ${newThemeName}.js. The link to \`common.js\` in the theme header has also been updated to use \`${newThemeName}.js\`. | |
| The \`common.js\` file contains the code for managing the cart (\`cart.add\`, \`cart.update\`, \`cart.remove\`), managing the whishlist and a bunch of other stuff. You may need to update this file if you are for example creating a custom cart in your theme and need to update the JS | |
| The file has been copied, renamed and relinked so you could make changes to the default JavaScript code without having to overwrite or OCMOD the default file. | |
| " > ${newThemeName}/README.md | |
| } | |
| # EXCEUTE | |
| copyDefaultTheme | |
| updateHeaderLinks | |
| changeStructure | |
| createFiles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment