Post by fegdeed » Fri Mar 15, 2019 2:13 am

So I came across this useful extension, sadly, the developers site is no more functional. It allows customers the ability to donate to charity before checkout. Here is the link https://www.opencart.com/index.php?rout ... _license=0 , what is the best way to convert that to work on Opencart 3.0.2? Thanks.

New member

Posts

Joined
Fri Sep 21, 2018 12:01 am

Post by thekrotek » Fri Mar 15, 2019 2:43 am

If you can code yourself, you can simply make this extension compatible with OC 3. Otherwise you may pay for it to another developer.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by straightlight » Fri Mar 15, 2019 6:23 am

For v3.0.2.0 and below (for v3.x releases), in admin/controller/extension/total/charity.php file, use the following:

Code: Select all

<?php 
class ControllerExtensionTotalCharity extends Controller { 
	private $error = array(); 
	 
	public function index() {
		$this->load->language('extension/total/charity');
	
		$this->document->setTitle($this->language->get('heading_title'));

		$this->load->model('setting/setting');
		
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
			$this->model_setting_setting->editSetting('total_charity', $this->request->post);
		
			$this->session->data['success'] = $this->language->get('text_success');
			
			$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true));
		}
		
		if (isset($this->error['warning'])) {
			$data['error_warning'] = $this->error['warning'];
		} else {
			$data['error_warning'] = '';
		}

		$data['breadcrumbs'] = array();

		$data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_home'),
			'href' 		=> $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
   		);

                $data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_total'),
			'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)
		);		
		$data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('heading_title'),
			'href' 		=> $this->url->link('extension/total/charity', 'user_token=' . $this->session->data['user_token'], true)
   		);
		
		$data['action'] = $this->url->link('extension/total/charity', 'user_token=' . $this->session->data['user_token'], true);
		                
		$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true);
		
		if (isset($this->request->post['total_charity_status'])) {
			$data['total_charity_status'] = $this->request->post['total_charity_status'];
		} else {
			$data['total_charity_status'] = $this->config->get('total_charity_status');
		}

		if (isset($this->request->post['total_charity_sort_order'])) {
			$data['total_charity_sort_order'] = $this->request->post['total_charity_sort_order'];
		} else {
			$data['total_charity_sort_order'] = $this->config->get('total_charity_sort_order');
        }
				
        if (isset($this->request->post['total_charity_gift'])) {
			$data['total_charity_gift'] = $this->request->post['total_charity_gift'];
		} else {
			$data['total_charity_gift'] = $this->config->get('total_charity_gift');
		}
                
        if (isset($this->request->post['total_charity_name'])) {
			$data['total_charity_name'] = $this->request->post['total_charity_name'];
		} else {
			$data['total_charity_name'] = $this->config->get('total_charity_name');
		}
		
		$data['header'] = $this->load->controller('common/header');
		$data['column_left'] = $this->load->controller('common/column_left');
		$data['footer'] = $this->load->controller('common/footer');		

		$this->response->setOutput($this->load->view('extension/total/charity', $data));
                }
                
	protected function validate() {
		if (!$this->user->hasPermission('modify', 'extension/total/charity')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}
		
		return !$this->error;
		}	
	}

In admin/view/template/extension/total/charity.twig file,

ensure to have the following:

Code: Select all

{{ header }}{{ column_left }}
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
            <div class="pull-right">
                <button type="submit" form="form-charity" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fa fa-save"></i></button>
                <a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
            <h1>{{ heading_title }}</h1>
            <ul class="breadcrumb">
			{% for breadcrumb in breadcrumbs %}
				<li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
			{% endfor %}
            </ul>
        </div>
    </div>
    <div class="container-fluid">
        {% if error_warning %}
            <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
                <button type="button" class="close" data-dismiss="alert">&times;</button>
            </div>
		{% endif %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-list"></i> {{ heading_title }}</h3>
            </div>
            <div class="panel-body">
                <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-charity" class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="input-name">{{ entry_charity_name }}</label>
                        <div class="col-sm-10">
                            <input type="text" id="input-name" class="form-control" name="total_charity_name" value="{{ total_charity_name }}" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="input-status">{{ entry_status }}</label>
                        <div class="col-sm-10">
                            <select name="total_charity_status" id="input-status" class="form-control">
                                {% if total_charity_status %}
                                    <option value="1" selected="selected">{{ text_enabled }}</option>
                                    <option value="0">{{ text_disabled }}</option>
								{% else %}
                                    <option value="1">{{ text_enabled }}</option>
                                    <option value="0" selected="selected">{{ text_disabled }}</option>
								{% endif %}
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="input-sort-order">{{ entry_sort_order }}</label>
                        <div class="col-sm-10">
                            <input type="text" name="total_charity_sort_order" value="{{ total_charity_sort_order }}" placeholder="{{ entry_sort_order }}" id="input-sort-order" class="form-control" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="input-gift">{{ entry_giftaid }}</label>
                        <div class="col-sm-10">
                            <select name="total_charity_gift" id="input-gift" class="form-control">
                                {% if total_charity_gift %}
                                    <option value="1" selected="selected">{{ text_enabled }}</option>
                                    <option value="0">{{ text_disabled }}</option>
								{% else %}
                                    <option value="1">{{ text_enabled }}</option>
                                    <option value="0" selected="selected">{{ text_disabled }}</option>
								{% endif %}
                            </select>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{{ footer }}
Then, see this post: viewtopic.php?f=202&t=210540&start=20#p750515

Then, in the install.xml file of the downloaded ZIP file,

replace:

Code: Select all

<file path="catalog/view/theme/*/template/checkout/cart.tpl"> 
            <operation>
                        <search><![CDATA[$coupon ||]]></search>
                        <add position="replace"><![CDATA[$charity || $coupon || ]]></add>
            </operation>
            <operation>
                        <search position="" ><![CDATA[<?php echo $coupon; ?>]]></search>
                        <add><![CDATA[<?php echo $charity; ?><?php echo $coupon; ?>]]></add>
            </operation>
        </file>
with:

Code: Select all

<file path="catalog/view/theme/*/template/checkout/cart.twig"> 
            <operation>
                        <search><![CDATA[$coupon ||]]></search>
                        <add position="replace"><![CDATA[{{ charity }} or {{ coupon }} or ]]></add>
            </operation>
            <operation>
                        <search position="" ><![CDATA[{{ coupon }}]]></search>
                        <add><![CDATA[{{ charity }}{{ coupon }}]]></add>
            </operation>
        </file>
Then, follow the FAQ: viewtopic.php?f=176&p=739789#p718325. This should resolved the issue.
Last edited by straightlight on Thu Mar 28, 2019 5:56 pm, edited 3 times in total.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by fegdeed » Fri Mar 15, 2019 10:25 am

Thanks @Straightlight, I followed your codes and the extension has been installed, I have allowed permissions and modifications at user groups > administrator, but when I try to save the charity name it says You do not have permission to access this page, please refer to your system administrator. Could there be something causing this restriction?

New member

Posts

Joined
Fri Sep 21, 2018 12:01 am

Post by xxvirusxx » Fri Mar 15, 2019 2:51 pm

For admin, replace current files with these.

In some places he forgot to change from extension/total in marketplace/extension and in twig in two places forgot to add total_ :)

My Extensions | OC 3.0.3.1, 3.0.2.0, 2.3.0.2 with bugs fixed.


Active Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm

Post by paulfeakins » Fri Mar 15, 2019 6:45 pm

Very good to see the community upgrading an extension here in the forum, carry on!

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by fegdeed » Fri Mar 15, 2019 6:58 pm

Thanks @xxvirusxx, permission warning is gone, but when I try to access the website on the front end, I get another warning...Warning: Invalid argument supplied for foreach() in /home/cpanel_username/storage/modification/system/engine/loader.php on line 83Notice: Undefined property: Proxy::getTotal in /home/cpanel_username/storage/modification/system/engine/action.php on line 79 .
I checked the code on loader.php in modification folder and around line 83 it says:

Code: Select all

// Overriding models is a little harder so we have to use PHP's magic methods
				// In future version we can use runkit
				foreach (get_class_methods($class) as $method) {
					$proxy->{$method} = $this->callback($this->registry, $route . '/' . $method);
				}
				
				$this->registry->set('model_' . str_replace('/', '_', (string)$route), $proxy);
			} else {
				throw new \Exception('Error: Could not load model ' . $route . '!');
			}
		}
	}
And on action.php in modification folder, around line 79, it says:

Code: Select all

if ($reflection->hasMethod($this->method) && $reflection->getMethod($this->method)->getNumberOfRequiredParameters() <= count($args)) {
			return call_user_func_array(array($controller, $this->method), $args);
		} else {
			return new \Exception('Error: Could not call ' . $this->route . '/' . $this->method . '!');
		}
	}
}
Thanks guys for all your help.

New member

Posts

Joined
Fri Sep 21, 2018 12:01 am

Post by xxvirusxx » Sat Mar 16, 2019 1:37 am

Not checked catalog files... :laugh: , but I will check.
paulfeakins wrote:
Fri Mar 15, 2019 6:45 pm
Very good to see the community upgrading an extension here in the forum, carry on!
Yep...and nobody give you to buy a beer. :laugh:
That's why I have removed almost all converted extension (50-60) from marketplace.

My Extensions | OC 3.0.3.1, 3.0.2.0, 2.3.0.2 with bugs fixed.


Active Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm

Post by straightlight » Sat Mar 16, 2019 4:19 am

- Fixed the admin controller codes
- Fixed the admin TWIG codes
- Fixed the catalog TWIG file not returning the right TWIG file.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by fegdeed » Sat Mar 16, 2019 9:42 am

Thanks @Straightlight, I am still getting the same error, I did refresh mod and caches...

New member

Posts

Joined
Fri Sep 21, 2018 12:01 am

Post by straightlight » Sat Mar 16, 2019 10:02 am

I tried my latest modifications on my end, I could not reproduce the issue you are describing. The page is loading as intended. The error you are describing is not originating from this extension ...

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Sat Mar 16, 2019 10:07 am

Fixed redirection from admin controller (not related with the foreach() error).

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by xxvirusxx » Sat Mar 16, 2019 1:52 pm

and charity model code from catalog/model/extension/total/charity.php ( code added to page 2)
Last edited by xxvirusxx on Thu Mar 28, 2019 3:30 pm, edited 1 time in total.

My Extensions | OC 3.0.3.1, 3.0.2.0, 2.3.0.2 with bugs fixed.


Active Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm

Post by straightlight » Sat Mar 16, 2019 9:26 pm

In catalog/model/total/charity.php file,

find:

Code: Select all

if ($this->session->data['giftaid'] == '1') {
                $ga = $this->language->get('text_yes');
            } elseif ($this->session->data['giftaid'] == '0') {
                $ga = $this->language->get('text_no');
            } elseif ($this->session->data['giftaid'] == 'no') {
                $ga = $this->language->get('text_thanks');
            };
                     
replace with:

Code: Select all

if (isset($this->session->data['giftaid'])) {
if ((int)$this->session->data['giftaid'] == 1) {
                $ga = $this->language->get('text_yes');
            } elseif (!$this->session->data['giftaid']) {
                $ga = $this->language->get('text_no');
            } elseif (trim(strtololower($this->session->data['giftaid'])) == 'no') {
                $ga = $this->language->get('text_thanks');
            }
}
Then, replace:

Code: Select all

if ($donation == '0') {
with:

Code: Select all

if (!$donation) {

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by fegdeed » Mon Mar 18, 2019 1:38 am

Thanks guys @Straightlight and @xxvirusxx, I'm now getting this error at checkout...

Code: Select all

Fatal error: Uncaught Twig_Error_Loader: Unable to find template "default/template/checkout/checkoutsimple.twig" (looked into: /home/cpanel username/website url/system/storage/modification/catalog/view/theme, /home/cpanel username/website url/catalog/view/theme). in /home/cpanel username/website url/system/library/template/Twig/Loader/Filesystem.php:215 Stack trace: #0 /home/cpanel username/website url/system/library/template/Twig/Loader/Filesystem.php(139): Twig_Loader_Filesystem->findTemplate('default/templat...') #1 /home/cpanel username/website url/system/library/template/Twig/Environment.php(312): Twig_Loader_Filesystem->getCacheKey('default/templat...') #2 /home/cpanel username/website url/system/library/template/Twig/Environment.php(378): Twig_Environment->getTemplateClass('default/templat...', NULL) #3 /home/cpanel username/website url/system/storage/modification/system/library/template/twig.php(42): Twig_Environment->loadTemplate('default/templat...') #4 /home/cpanel username/website url/system/library/template.p in /home/cpanel username/website url/system/library/template/Twig/Loader/Filesystem.php on line 215

New member

Posts

Joined
Fri Sep 21, 2018 12:01 am

Post by straightlight » Mon Mar 18, 2019 2:04 am

Fatal error: Uncaught Twig_Error_Loader: Unable to find template "default/template/checkout/checkoutsimple.twig"
Not related to this extension. Ensure to upload that missing file on the specified path from the Checkout Simple extension you might have.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by fegdeed » Mon Mar 18, 2019 4:59 am

Thanks @Straightlight, I seem to not have anything related to checkoutsimple....If its okay with you, can you please attach the zip file of the charity you used at your end?

New member

Posts

Joined
Fri Sep 21, 2018 12:01 am

Post by straightlight » Mon Mar 18, 2019 5:16 am

Send me a PM, I will take a look.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by xxvirusxx » Mon Mar 18, 2019 5:18 am

I think catalog files need to be moved in Total like coupon, voucher.
install. xml not needed anymore, because in cart.twig there is no code like in xml.

My Extensions | OC 3.0.3.1, 3.0.2.0, 2.3.0.2 with bugs fixed.


Active Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm

Post by straightlight » Mon Mar 18, 2019 5:23 am

However, this path is still unexplained where no extension path nor sub-folders are required:
default/template/checkout/checkoutsimple.twig

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 27 guests