So, I'm using OpenCart 1.4.9.
What I want to do is grab a variable made by a custom shipping product.
The table in which it's coming from is product and the column is shipping_by_product:
I want to add a little picture when browsing through the categories so they can see it's free shipping.
Now, I was able to add this in the product detail (product.tpl template):
Using this code:
<?php if($product_info['shipping_by_product'] == '0.0000'){ ?>
<img src="LINK HERE" alt="Recommended by MADNESS">
<br />
<?php
}
?>
But that code doesn't work in category.tpl (The category template)
I get an undefined index error for $product_info and for shipping_by_product.
So I was thinking of just running a query to grab the information from the database and then add the conditional, or what other way can I do it?
Data is passed to the template by the controller, which gets it from the model (data layer). You might have to customize the controller and model to get that data if it isn't already passed. You can use the vqmod extension to add your own code in without changing the core code. Look here for info on the extension.
Figured it out.
Added: 'shipping_by_product' => $result['shipping_by_product'], to category.php
As I learned $result is pretty much the same as $product_info in this file.
Then I used this for my code:
<?php if($products[$j]['shipping_by_product'] == '0.0000'){ ?> <img style="position: absolute;margin-left: -100px;" src="IMAGE " alt="Free Continental US shipping!"> <br /> <?php } ?>
:)
Related
I have been trying to display a product attribute that i created called “PDF” in a tab. I tried to re-use the code that had been used to get the product description but change it to reference my new Attribute, well so i thought.
This is the code i used:
The attribute code is: pdf
Admin title is: PDF
<?php $_pdf = $this->getProduct()->getPDF(); ?>
<?php if ($_pdf): ?>
<h2><?php echo $this->__('PDF') ?></h2>
<div class="std">
<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_pdf, 'pdf') ?>
</div>
<?php endif; ?>
I maybe no where near where i have to be but i am new to magento and new to PHP as well.
I dont want to have to use any extensions if possible.
If you can fix this for me you will be a god! thanks in advance for any help.
You are using $this->getProduct()->getPDF() when you should be using $this->getProduct()->getPdf(). Magento camel cases attribute names for its magic methods.
You could also use $this->getProduct()->getData('pdf').
I want to be able to add an image next to the title of an article (and be able to select the image for each article - not just a one and done setting). I modified the /administrator/components/com_content/models/forms/article.xml file by adding these fields at the top of the section:
<field
name="titleImage"
type="media"
label="Title Image"
description="Image that will be displayed next to the article's title." />
<field
name="spacer0"
type="spacer"
hr="true"
/>
This adds the parameter to the Edit Article page and lets me select an image.
I added this code to my theme's com_content/article/default.php page (inside the if ($params->get('show_title')) block):
<?php if($this->params->get('titleImage')){ ?>
<img class="titleImage" src="<?php echo htmlspecialchars($images->titleImage); ?>" alt="Title Image" />
<?php } ?>
The image is not appearing on the page. I'm new to Joomla so it may be obvious, but what am I missing?
Thanks!
In 2.5 there is already a standardized image field (actually 2) and all you have to really do is make a layout override to put the images where you want them.
YOu should modify the form using a plugin if you go that route. I would modify the image field to add a third image if you are already using the two of hem.
After some testing I found out why it wasn't working:
Firstly, you need to ensure you add the field to a specific place in article.xml. I would suggest adding it before or after <field name="show_title"> on line 127
Then, you can call the parameter like so:
<?php if ($params->get('titleImage')) : ?>
<img class="titleImage" src="<?php echo JURI::root() . $params->get('titleImage'); ?>" alt="Title Image" />
<?php endif; ?>
Hope this helps
I am using OpenCart. I want to give a link from product_form.tpl to another page. I mean I have added a tab called 'Allocation' in which I have given a button 'Add Allocation' which should redirect an external page. I'd like also to provide the product_id within this link but it's not working properly...
Here is my code (product_form.tpl)
<div id="tab-allocate">
<table class="list"><tr><td align="center">ADD ALLOCATION</td></tr></table>
</div>
But allocation.php?product_id=&product_id is not working, it goes to allocate.php page
but doesn't carry the product_id. What am I doing wrong?
I think, it's something wrong in your passing parameter, please try like that
<a href="allocation.php?product_id=product_id" target="_blank" class="copybutton" style="width:120px;">
Your previous style work to pass two parameter. eg
<a href="allocation.php?product_id=product_id&second_id=Second_id" target="_blank" class="copybutton" style="width:120px;">
Hope this help
Ps. You can also use like that
$this->request->post['product_id'] OR $this->request->get['product_id']
What a messy HTML...
Change that link to this one:
ADD ALLOCATION
This should work. And put the CSS styles into the CSS files (catalog/view/themes/<YOUR_THEME>/css/stylesheet.css).
This is my very first question at StackOverflow.
I was trying to post comment in the post Can a Joomla module "know" what position it's in?, but could find no way to do that so I have to post another question here. Any tips regarding how to do this properly is greatly apprieciated.
Anyway, here is my questions:
I tried the code mentioned in the above post but it seemed didn't work. I'm not only quite new to PHP, but also coding, so I'm not sure if it's me or the code. here's what I did to the module's default.php file:
1)to ensure I insert the code at the right place, I insert
<?php echo(print_r($module)); ?>
and it output 1 at the right position;
2)the position-name that I need to determine is "showcase-a", so I insert code
<?php if ($module->position == 'showcase-a'):?>test<?php endif;?>
to the above place, but this time it does't show anything;
3)then I tried this code:
<?php if ($module):?><span>test</span><?php endif; ?>
But still it does't display "test" at the position as I expected.
4)I tried
<?php if (1):?><span>test</span><?php endif; ?>
and the test "test" displays as good. So I didn't code the IF statement wrong.
Now I'm totally lost. Since print_r($module) outputs 1, $module must be positive, why PHP ignore test in 3)? This is just a side question for the sake of PHP learning. What I still need to solve is let the module determine which position itself is in.
Please help. Thank you!
I'm not sure about using it in the template (although it doesn't seem wrong altogether) but my modules oftentimes access the position like this:
$module->position
in the module (so mod_something.php) so try to put it there, if it's available just set a variable and it will be available in the view too.
If $module->position didn't work for you. $module->position may only work for joomla 1.7, 2.5 and + but i'm not sure. $module->position works in joomla 2.5.
Otherwise you need to make a module.php function
Check out the file
/templates/you-template/html/modules.php
For example you make your position the following in your template (for example index.php)
<jdoc:include type="modules" name="header" style="includeposition" />
inside of
/templates/you-template/html/modules.php
You make a function like this :
<?php
function modChrome_includeposition($module, &$params, &$attribs){
//Set a value to $module->position
$module->position='WHATEVER YOUWANT';
?>
<div class="moduletable <?php echo $params->get('moduleclass_sfx').' '.$module->name; ?>">
<?php
if($module->showtitle){
?>
<div class="modtitle">
<div class="fleche">
<span>
<?php
echo $module->title;
?>
</span>
</div>
</div>
<?php
}
?>
<div class="modcontent">
<?php echo $module->content; ?>
<div class="clear">
</div>
</div>
</div>
<?php
}
?>
make different functions names that sets different values if needed.
the function name will match the syle you set:
modChrome_includeposition($module, &$params, &$attribs)
because
style="includeposition"
inside of your jdoc.
I am using drupal 7
views-view--myview.tpl.php sample code
<?php if ($rows): ?>
<?php print $rows; ?>
When i see this in firebug i see the structure
<div class="item-list">
<ul>
<li class="views-row views-row-1 views-row-odd views-row-first"> </li>
<li class="views-row views-row-2 views-row-even "> </li>
Now how do i inject a div in each of these li.. Is this possible without using jquery?
If you go the the "Edit" page for the view, you should see a link called "Theme: Information". It's under the "Style Settings" section. If you click this, you can see a list of all the possible template that your theme will look for when displaying the view. In bold will be the file it is currently using.
views-view--myview.tpl.php is to high up the chain to do what you want. If you want to inject a div (the same div) around each field you output, then I think the file views-view-field.tpl.php is what you are looking for.
The file contains just the line
<?php print $output; ?>
So there you can insert the desired div (after you copy it from views/themes into the template directory for your theme, of course).
If you investigate the Theme Information link some more it describes how to be even more specific in naming the view template files, for example if you wanted to theme a specific row differently you could use the file views-view-field--entity-id-X.
Hope that helps!
EDIT for comment
To go a different route, you can also edit the field settings for your view. Under the Field tab on the edit view page, you can click the links for each field. There is a Suffix setting available you could use to inject a div after the field is displayed.