Post by Joe1234 » Tue Aug 09, 2022 10:34 am

I have a page that I made so many changes to it doesn't make sense doing the individual edits. How do I replace the whole page without overwriting the core page? Does upload replace an existing file, or move the uploaded file to the modifications folder if it already exists? Or is there a way to search and replace an entire files contents?

v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by halfhope » Tue Aug 09, 2022 2:15 pm

Hi!

Use you can use ocmod "offset" attribute to replace all file content.

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Modification Default</name>
    <version>1.0</version>
    <author>OpenCart Ltd</author>
    <link>http://www.opencart.com</link>
    <file path="catalog/controller/common/home.php">
        <operation>
            <search><![CDATA[<?php]]></search>
            <add position="replace" offset="100"><![CDATA[
            test123
            ]]></add>
        </operation>
    </file>  
</modification>

My extensions in marketplace. [ security | flexibility | speedup ]


User avatar
Active Member

Posts

Joined
Tue Dec 10, 2013 9:44 pm
Location - San Diego

Post by paulfeakins » Tue Aug 09, 2022 6:13 pm

Joe1234 wrote:
Tue Aug 09, 2022 10:34 am
Does upload replace an existing file
You mean by FTP? How would any OpenCart code possibly interfere with you uploading over the top of a file by FTP?

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by Joe1234 » Wed Aug 10, 2022 12:25 am

@halfhope, thanks. I was hoping to avoid basically putting an entire file of code inside the install file. I would think since ocmod was...I'm assuming...designed to avoid replacing core files it would work off the logic of seeing an existing file during the upload and copy that to the modification folder instead. Oh well, you work with what you have right.

v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by DigitCart » Wed Aug 10, 2022 1:41 am

Hi

If it is a view file, You can do it like this:

Code: Select all

<file path="catalog/controller/common/home.php">
	<operation>
		<search><![CDATA[$this->load->view('common/home', $data)]]></search>
		<add position="replace"><![CDATA[$this->load->view('common/home2', $data)]]></add>
	</operation>
</file>
If it is not a view file, This is how I did it in one of my extensions using the event system:

Code: Select all

$this->load->model('setting/event');

$this->model_setting_event->addEvent('checkout_success', 'catalog/controller/checkout/success/before', 'extension/module/checkout_success/changeRoute');

Code: Select all

public function changeRoute(&$route = '', $data = array(), $output = '') {
	$route = 'extension/module/checkout_success';
}
This changes the default page to the custom page.

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by Joe1234 » Sat Aug 13, 2022 1:08 am

@Digitcart, I like that idea, I'll keep that in mind.

v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am
Who is online

Users browsing this forum: Bing [Bot], ravikumar22, Semrush [Bot] and 82 guests