Calculate and display discounted price using vQmod on OpenCart - php

There is a php vqmod that adds how much of a discount a person gets for quantity but I need to to also have another thing that says "15% OFF if you share us, new price $HERE"
I just need the PHP modified so the it takes the regular price of the item and calculate how much it cost with a 15% discount and display the discounted price . Here is the code of the php vqmod. can anyone please help me?
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<code>you_save</code>
<name>You Save OCMOD Product (edited red)</name>
<version>1.1.0</version>
<author>Sam custom</author>
<link></link>
<file path="catalog/controller/product/product.php">
<operation>
<search><![CDATA[
$data['text_tags'] = $this->language->get('text_tags');
]]></search>
<add position="after"><![CDATA[
$data['text_you_save'] = $this->language->get('text_you_save');
$data['text_you_save_or'] = $this->language->get('text_you_save_or');
]]></add>
</operation>
<operation>
<search><![CDATA[
$data['special'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
]]></search>
<add position="after"><![CDATA[
$data['you_save'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')) - $this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
$data['you_save_or'] = round((($product_info['price'] - $product_info['special']) / $product_info['price'] * 100));
]]></add>
</operation>
<operation>
<search><![CDATA[
foreach ($discounts as $discount) {
]]></search>
<add position="after"><![CDATA[
$you_save = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')) - $this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
if ($product_info['price'] == 0) { $you_save_or = 0; } else { $you_save_or = round((($product_info['price'] - $discount['price']) / $product_info['price'] * 100)); }
]]></add>
</operation>
<operation>
<search><![CDATA[
'quantity' => $discount['quantity'],
]]></search>
<add position="after"><![CDATA[
'you_save' => $you_save,
'you_save_or' => $you_save_or,
]]></add>
</operation>
</file>
<file path="catalog/language/english/product/product.php">
<operation>
<search><![CDATA[
// Entry
]]></search>
<add position="before"><![CDATA[
$_['text_you_save'] = 'You save:';
$_['text_you_save_or'] = 'or';
]]></add>
</operation>
</file>
<file path="catalog/view/theme/*/template/product/product.tpl">
<operation>
<search><![CDATA[
<h2><?php echo $special; ?></h2>
]]></search>
<add position="after"><![CDATA[
</li><li><span style="font-size:12px;font-weight:600;color:red"><?php echo $text_you_save; ?></span> <span style="font-size:12px;font-weight:400"><?php echo $you_save; ?> <?php echo $text_you_save_or; ?> <?php echo $you_save_or; ?>%</span>
]]></add>
</operation>
<operation>
<search><![CDATA[
<li><?php echo $discount['quantity']; ?><?php echo $text_discount; ?><?php echo $discount['price']; ?></li>
]]></search>
<add position="after"><![CDATA[
<li><span style="font-size:12px;font-weight:600;color:red"><?php echo $text_you_save; ?></span> <span style="font-size:12px;font-weight:400"><?php echo $discount['you_save']; ?> <?php echo $text_you_save_or; ?> <?php echo $discount['you_save_or']; ?>%</span></li>
]]></add>
</operation>
</file>
</modification>

Related

Add Shipping Method To Opencart 2.0.2.0

I have this code that works with Opencart 1.5, it adds the Shipping Method to the order list, I have changed it to flag on Express Shipping, however I don't really know what I am missing to make it work for Opencart 2.0.
<modification>
<id>Shipmethod</id>
<version>1.0.</version>
<vqmver>2.1.x</vqmver>
<author></author>
<file name="admin/model/sale/order.php">
<operation>
<search position="replace" regex="true"><![CDATA[~SELECT o.order_id,~]]></search>
<add><![CDATA[SELECT o.order_id, o.shipping_method,]]></add>
</operation>
</file>
<file name="admin/controller/sale/order.php">
<operation>
<search position="before"><![CDATA['action' => $action]]></search>
<add><![CDATA['shipping_method' => $result['shipping_method'],]]></add>
</operation>
</file>
<file name="admin/view/template/sale/order_list.tpl">
<operation>
<search position="before"><![CDATA[<td class="left"><?php if ($sort == 'o.date_added') { ?>]]></search>
<add><![CDATA[
<td style="width:125px">Express Shipping</td>
]]></add>
</operation>
<operation>
<search position="before"><![CDATA[<td><input type="text" name="filter_date_added"]]></search>
<add><![CDATA[<td></td>]]></add>
</operation>
<operation>
<search position="before"><![CDATA[<td class="left"><?php echo $order['date_added']; ?></td>]]></search>
<add><![CDATA[<td class="left" style="color:red;"><?php if ($order['shipping_method'] === "3. UK Express Delivery") {echo "YES";};?></td>
]]></add>
</operation>
</file>
</modification>
Any help to make it work with Opencart 2.0 would be great :)
FYI, Opencart v2.0.0.0 is slightly different from version 1.5.6.4 or below.
So you have to modified your vqmod xml file. You can check with following code
<modification>
<id>Shipmethod</id>
<version>1.0.</version>
<vqmver>2.1.x</vqmver>
<author></author>
<file name="admin/model/sale/order.php">
<operation>
<search position="replace" regex="true"><![CDATA[~SELECT o.order_id,~]]></search>
<add><![CDATA[SELECT o.order_id, o.shipping_method,]]></add>
</operation>
</file>
<file name="admin/controller/sale/order.php">
<operation>
<search position="before"><![CDATA['status' => $result['status'],]]></search>
<add><![CDATA['shipping_method' => $result['shipping_method'],]]></add>
</operation>
</file>
<file name="admin/view/template/sale/order_list.tpl">
<operation>
<search position="before" offset="0"><![CDATA[<td class="text-left"><?php if ($sort == 'status') { ?>]]></search>
<add><![CDATA[
<td style="width:125px">Express Shipping</td>
]]></add>
</operation>
<operation>
<search position="before"><![CDATA[<td class="text-left"><?php echo $order['status']; ?></td>]]></search>
<add><![CDATA[<td class="left" style="color:red;"><?php if ($order['shipping_method'] === "Flat Shipping Rate") {echo "YES";};?></td>
]]></add>
</operation>
</file>

OpenCart2 vqmod replace,before and after all replacing?

Please take a look at the following xml file in the vqmod folder.
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<id>Drop Shipping</id>
<version>2.0.0</version>
<vqmver required="true">2.4.0</vqmver>
<author>South Coast Hosting Services (Pty) Ltd</author>
<file name="admin/language/*/common/menu.php">
<operation error="log">
<search><![CDATA[// Text]]></search>
<add position="after"><![CDATA[
$_['text_gdropship_menu'] = 'Drop Shipping';
$_['text_gdropship_setup'] = 'Drop Shipping Setup';
]]></add>
</operation>
</file>
<file name="admin/controller/common/menu.php">
<operation error="log">
<search ><![CDATA[$this->load->language('common/menu');]]></search>
<add position="after"><![CDATA[
$data['text_gdropship_setup'] = $this->language->get('text_gdropship_setup');
$data['text_gdropship_menu'] = $this->language->get('text_gdropship_menu');
]]></add>
</operation>
<operation error="log">
<search><![CDATA[$data['home'] = $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL');]]></search>
<add position="before"><![CDATA[
$data['gdropshipmenu'] = $this->url->link('custom/gdropship', 'token=' . $this->session->data['token'], 'SSL');
$data['home'] = $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL');
]]></add>
</operation>
</file>
<file name="admin/view/template/common/menu.tpl">
<operation error="log">
<search><![CDATA[<li id="system"><a class="parent"><i class="fa fa-cog fa-fw"></i> <span><?php echo $text_system; ?></span></a>]]></search>
<add position="before"><![CDATA[<li><a class="parent"><i class="fa fa-share-alt fa-fw"></i><span><?php echo $text_gdropship_menu; ?><span></a>
<ul>
<li><?php echo $text_gdropship_setup; ?></li>
</ul><li id="system"><a class="parent"><i class="fa fa-cog fa-fw"></i> <span><?php echo $text_system; ?></span></a>]]></add>
</operation>
</file>
</modification>
This runs perfectly, linking to an admin page create in this question. You will see that the position tags contain 'after' and 'before' options. My problem is (besides taking all day to figure this out and do these few lines) is that both these tags seem to replace instead of doing a before or after. Changing them to replace has no effect. Hence I just included the code I was 'After-ing'.
So my question is have I done something wrong with the above code? I would just like to clarify before proceeding with development so it does not bite me down the line. It could be just another OC2 newbie.
Thank you.
PS Perhapse considering what's new a new tag for Opencart2 is warranted?
There is nothing wrong with your vQmod searches or replaces. The issue is you've formatted the search and replace parameters to those of OCMod, with the position="XXX" in the <add> tag instead of the <search> tag as per vQmod's format. Swapping those should fix the problem

Edit a controller using XML file in Open cart

My Code is in a single xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created using vQModerator's XML Generator by The Wizard of Osch for http://www.crystalcopy.nl //-->
<!-- (Based on vQmod XML Generator by UKSB - http://www.opencart-extensions.co.uk) //-->
<modification>
<id><![CDATA[vQModerator Installation]]></id>
<version><![CDATA[1.1.6]]></version>
<vqmver><![CDATA[2.4.1]]></vqmver>
<author><![CDATA[Nidhishanker Modi]]></author>
<file name="catalog/view/theme/shopitout/template/common/header.tpl" error="abort">
<operation info="">
<search position="Replace" offset="" ><![CDATA[<img src="<?php echo $logo; ?>" title="<?php echo $name; ?>" alt="<?php echo $name; ?>" />]]></search>
<add><![CDATA[<img src="image/data/my_logo.png" title="<?php echo $name; ?>" alt="<?php echo $name; ?>" />]]></add>
</operation>
</file>
<file name="catalog/controller/module/slideshow.php" error="">
<operation info="">
<search position="After" ><![CDATA[
$results = $this->model_design_banner->getBanner($setting['banner_id']);
]]></search>
<add><![CDATA[echo "Testing Data to hold screen"; exit; ]]></add>
</operation>
</file>
</modification>
Now Friends the second file tag is replacing my search data always. Even i am not giving postion="replace".
where i am wrong please give me suggestions.
There is an error in your first file tag code. Most probably:
Wrong file location (catalog/view/theme/shopitout/template/common/header.tpl) .
Or mentioned search code doesn't exist in catalog/view/theme/shopitout/template/common/header.tpl
Proof for the above statements:
Move the second file tag to first - Working.
Or remove the error="abort" parameter form first file tag - 2nd file code Working
if you still can't find the error, then refer the section under the heading - Opencart Vqmod xml file not working?? in https://sankartypo3.wordpress.com/2013/11/25/opencart-vqmod-tutorial/
Have a nice day!!

How to make a xml file in opencart for edit and model and controller

I am new to Open cart and working with VQmod and tried this code for editing my header logo and some text.
<file name="catalog/view/theme/shopitout/template/common/header.tpl" error="abort">
<operation info="">
<search position="Replace" offset="" ><![CDATA[<img src="<?php echo $logo; ?>" title="<?php echo $name; ?>" alt="<?php echo $name; ?>" />]]></search>
<add><![CDATA[<img src="image/data/my_logo.png" title="<?php echo $name; ?>" alt="<?php echo $name; ?>" />]]></add>
</operation>
</file>
</modification>
Now i want to write such code for edit a controller and model.
please tell how can we make such code or xml for model and controller.
In between </file> and </modification> tags add:
<file name="###File name with path of controller/ model file ###" >
<operation info="###Operation Info###" >
<search position="###Search/Replace filter###" regex="false" ><![CDATA[###Search Code###]]></search>
<add><![CDATA[
###Add Code###
]]></add>
</operation>
</file>
Reference link: Opencart Vqmod tutorial

How to fix "DOM UNABLE TO LOAD" error of vqmod in opencart

I want to add a new submenu under the catalog in the admin of the opencart using Vqmod. Here is my code:
<modification>
<id>add menu</id>
<author>XXX</author>
<version>2.3</version>
<vqmver>1.0.8</vqmver>
<!-- OPTION CONTROLLER -->
<file name="admin/controller/common/header.php">
<operation>
<search position="after"><![CDATA[
$this->data['text_newmenu'] = $this->language->get('text_newmenu');
]]></search>
<add><![CDATA[
$this->data['text_newmenu'] = $this->language->get('text_newmenu');
]]></add>
</operation>
<operation>
<search position="after"><![CDATA[
$this->data['doctor'] = $this->url->link('catalog/doctor', 'token=' . $this->session->data['token'], 'SSL');
]]></search>
<add><![CDATA[
$this->data['newmenu'] = $this->url->link('catalog/newmenu', 'token=' . $this->session->data['token'], 'SSL');
]]></add>
</operation>
</file>
<!-- OPTION LANGUAGE -->
<file name="admin/language/english/common/header.php">
<operation>
<search position="after"><![CDATA[
$_['text_zone'] = 'Zones';
]]></search>
<add><![CDATA[
$_['entry_newmenu'] = 'Wow sexy';
]]></add>
</operation>
</file>
<!-- header.tpl for new menu-->
<file name="admin/view/template/common/header.tpl">
<operation>
<search position="after"><![CDATA[
<li><?php echo $text_doctor; ?></li>
]]></search>
<add><![CDATA[
<li><?php echo $text_newmenu; ?></li>
]]></add>
</operation>
</file>
<modification>
But there is an error comes in DOM UNABLE TO LOAD: /opt/lampp/htdocs/work/oc/vqmod/xml/addmenu.xml
Does any one know whats the problem in my code?
I Was facing the similar problem. I had given the permission to the file. But still it was saying unable to load. After little research i found that it had admin permission and no read permission from others, which can be given by :
sudo chmod a+r filename
if you want to give to entire directory, then
sudo chmod -R a+r directory/
and this fixed my bug..
Hope it helps
addmenu.xml please validate this xml using an xml validator like this
http://www.xmlvalidation.com/
The error is because xml file is not a valid one
If this doesn't solve the problem , then try adding
<?xml version="1.0" encoding="UTF-8"?>
at top of the xml
Do you have any non-standard characters in your author tag such as á é í ó ú? If so, make sure you put them in CDATA tags as well as putting the
<?xml version="1.0" encoding="UTF-8"?>
header at the very start of the document (with absolutely nothing before it)

Categories