how to display the upc in product page with opencart3? - php

I want to display the upc in product page with opencart 3. How do I do that?
I added the below code into my template file /catalog/view/theme/default/template/product/product.twig,but it doesn't work.
{% if upc %}
{{ upc }}
{% endif %}

Please do not forget to backup these files first.
You have to add upc as a variable to the controller first and then echo it in the template.
in order to do that:
first edit controller file:
/catalog/controller/product/product.php
and search for
$data['model'] = $product_info['model'];
after that add:
$data['upc'] = $product_info['upc'];
and save the file.
After that your code in template file that you mentioned will work.
ps: by this approach you lose these changes if you update opencart.A better approach would be to make an ocmod extension for it.

Related

How to replicate a shortcode inside template

In wordpress functions.php file I have a shortcode that allows me to display the order ID when I'm on the view-order.php page. The shortcode works fine.
What I am trying to do is find a more comfortable alternative to this. So I would like to take advantage of the Twig template, so I'm doing some testing. I'm actually viewing the order ID, but it stays the same for every order I decide to view.
Example:
if I view the order 001, the ID 001 is shown (correct)
if I view the order 002, the ID 001 is shown (incorrect)
With the shortcode this does not happen, I can correctly display the ID of each order. Can anyone tell me where I'm doing wrong?
I've already done the same thing with my-orders page and my-downloads page, it worked fine, but for some reason it's not working with view-order.php page.
I appreciate any response, thanks.
add_shortcode( 'view_order_id' , 'view_order_00' );
function view_order_00(){
$order_id = absint( get_query_var('view-order') );
$order = new WC_Order( $order_id );
return $order->get_id();
}
{% set post = system.get.order_id|php('get_post') %}
{% set order = post.ID|php('wc_get_order') %}
{% for item in order.get_items %}
{% for download in order.get_downloadable_items %}
<div>{{post.ID}}</div>
{%endfor%}
{% endfor %}
I am using a third party plugin called e-addons, this offers many widgets for elementor, including Twig Template.
I contacted plugin support and they told me that I would have to pass the order ID in $ _GET to fix the problem. Furthermore, all this must be done in a dedicated elementor page and not in the view-order.php template as I was doing initially.
So here is a brief explanation of what I did step by step to fix the problem. I hope it will be useful to anyone who has had the same difficulties as me.
1. I created a new page with elementor titled test page. The
2. I copied the permalink of the newly created page (test-page) and put it in a filter in the functions.php file, here it is below.
// When you click on view order, this filter allows you to redirect from view-order (original woocommerce endpoint) to a custom page created with elementor.
function filter_woocommerce_get_endpoint_url( $url, $endpoint, $value, $permalink ) {
// Specific endpoint: If in the advanced settings of woocommerce you have changed the endpoint view order, then below you have to replace view-order with the one you have chosen in the advanced settings wi WC
if ( $endpoint === 'view-order' ) {
// New URL: change test-page with permalink of the page you created earlier. The /?order_id= part should not be removed.
$url = $permalink . 'test-page/?order_id=' . $value;
}
return $url;
}
add_filter( 'woocommerce_get_endpoint_url', 'filter_woocommerce_get_endpoint_url', 10, 4 );
3. After setting the filter with the permalink we need to modify the new page with elementor. Once in the editor I selected the e-Addons Posts Query widget and dragged it to the page area.
Step 3 opens here, follow these steps to configure the widget correctly, only change what is mentioned below:
Go to the Query Tab of the query posts widget
Query
In query type select Post Type
In options> post type select order
in post status select Any
Query Filter
in "By" select Meta Key
in Mtakey Filters add new and modify as follows
in Post Field custom meta key select _customer_user
in Value Type select Numeric
in Compare operator select "="
in Post Field Value select User Field
If you do everything correctly in step 3, the user will be able to view the orders, otherwise if you do something wrong you get nothing.
Here ends step 3.
4. Then go to the first tab of the widget entitled Content. Here you have to go to the menu item titled Post Items, and this is where I played with the Twig template. So the code I originally posted in my question now works.
{% set post = system.get.order_id|php('get_post') %}
{% set order = post.ID|php('wc_get_order') %}
{% for item in order.get_items %}
{% for download in order.get_downloadable_items %}
<div>{{post.ID}}</div>
{%endfor%}
{% endfor %}
Now, when I am on the order history page and click on view order I am redirected correctly to the specific order page which for example is mywebsite.com/account/test-page?order_id=xxxxxx

How do I use variables in a different place?

I'm trying to use a variable in a different place but it doesn't seem to be working.
Basically the idea that we had is to use the data you assign in the admin panel for your contact info that will be displayed on the contact page onto our footer. But whenever we try to use {{ location.adress }} in our footer.twig file it returns nothing.
To insert anything in view in .twig file you have to determine it in corresponding controller file, like #K. B. said.
In this particular case open /catalog/controller/common/footer.php
Find
$data['newsletter'] = $this->url->link('account/newsletter', '', true);
Add after
$data['address'] = nl2br($this->config->get('config_address'));
Now open /catalog/view/theme/YOUR_THEME/template/common/footer.twig
And place anywhere you need
{{ address }}
Than clear TWIG cache. Done. Now the address from the settings is in your footer.
If you wish to retrieve some data in your template, you must declare that data in corresponding controller file. For example if need retrieve {{ address }} it should be declared $data['address'] = 'data_retrieved_from_db'; For admin and for catalog are different files.

October CMS - Conditionally Load a Different Page

I'm in the process of building a site in October CMS that uses a slash page. The splash page is only supposed to show to non cookied users the first time that they visit the site. I am controlling this part via a component in a plugin called splash. Here is my onRun() function:
public function onRun()
{
$key = 'shownsplash';
if(!Session::has($key) || !Cookie::get($key))
{
$this->page['showsplash'] = true;
Cookie::queue('shownsplash',true);
Session::put($key,true);
$resp = NULL;
}
}
In my main page layout called 'default' I want to conditionally load the splash page template called 'splash' using the following:
{% if showsplash %}
{{ loadpage('splash') }}
{% else %}
Regular page template
{% endif %}
Except that I'm not sure how to load a page conditionally. One additional requirement is that the splash page takes the url http://www.example.com and not any subsequent pages. Can anyone point out how to do this?
in octobercms cms/page are hit by url , the url set in the config section and are bound to a layout. so for me page are more 'routing' object than html content holder.
In fact partials ARE html content holder
So if i had to do the same thing as you mean i would use partial and page.
a page with url="/" and two partials, one for the regular page and one for the splash.
bind your plugin component to the page not the layout
{% if showsplash %}
{% partial 'home/splash.htm' %}
{% else %}
{% partial 'home/regular.html' %}
{% endif %}
I think partial are exactly what to use in this kind of conditional stuff.
generaly think of
layout as website structuration
page mainly for routing
partial for html content

How to use wordpress template is_single() in twig template

I have this include file with following code. I assume I can used wordpress is_single() to twig template file. When I tried to accessing the detail page of a wordpress post this display the word Nothing.
Even though I have a post name foo post and I did also create a rev_slider named foo post.
{% if wp.is_single('foo post') %}
{{ wp.do_shortcode('[rev_slider foo post]')|raw }}
{% else %}
Nothing
{% endif %}
Am I doing this correctly?
Your code is correct, but just be sure you have the right post title or the right post name is wp.is_single()

Symfony2 - theme for multiple forms

Is there way to use diffrent themes for two (or more) forms on the same page.
I've 2 forms and I'd like to use theme "X" for first form and theme "Y" for second form.
You need to declare your theme before displaying your form.
You should try :
{% form_theme form 'ThemeX.html.twig' %}
{{ form(formX) }}
{% form_theme form 'ThemeY.html.twig' %}
{{ form(formY) }}
If that doesn't work (ie. second form theme declaration doesn't overwrite the first one), just use a separate template for your second form and insert it in your parent template using an include.
Try [http://symfony.com/doc/current/cookbook/form/form_customization.html#child-forms](this page) of symfony doc for more information

Categories