how can I display opencart total on external web page from cart - php

How can I display the $total on an external web page from opencart. The web page and opencart are on the same server but opencart is installed in a sub folder. I would like to display the Total and a link back to opencart. I have the link as follows so far:
<div id="topcart">
<p>
<span class="cartamt">$123.00</span>
<img src="/images/icon-cart.png" alt="Cart" />
</p>
</div><!-- end div topcart -->
I just need to replace the 123.00 with the actual total amount in opencart.
Thanks,
Robert Campbell

The simplest way to do this would be to save the total as getTotal() is called in the cart class to a session variable, and then use the session variable in that page (assuming they are on the same domain and using the same session). To set the session variable, use
$this->session->data['currentTotal'] = $total;
Just before return $total; in system/library/cart.php. Adding currency formatting gets a little more tricky. You instead need to use
global $registry;
$this->session->data['currentTotal'] = $registry->get('currency')->format($total);
After that, in your non OC page start a session if it's not already started, and add
<?php echo empty($_SESSION['currentTotal'] ? '$0.00' : $_SESSION['currentTotal']); ?>
In the place of your $123.00

To anyone else trying to find this answer it's simple. Edit the system/library/cart.php file like jay says but when getting the total use
$_SESSION['default']['currentTotal'] instead.

Related

Adding Javascript code to specific pages using Prestashop Module

I'm developing a custom Prestashop Module. The requirement is simple: Add a predefined block of javascript code to specific sections of the shopping process. Those are:
Home page
Product page
Product added to cart
Purchase completed
The code will be specific to each page.
I already read the basics of module development, but I can't find documentation for this specific functionality.
I already have a working module that is installable and configurable from the back office admin. I'm assuming I need to extend the footer and check the page currently being served, but I have no idea how to do this.
It's more simple than it appears :), you have to check in which page you are, in your hookDisplayHeader method add some if:
public function hookDisplayHeader($params){
/* some code */
// check if we are in homepage
if($this->context->controller->php_self == 'index'){
$this->context->controller->addJS('path-to-index-js');
}
// check if we are in product page
if($this->context->controller->php_self == 'product'){
$this->context->controller->addJS('path-to-product-js');
}
// and so on for all other pages
/* ... */
/* some code */
}
Also there is a global variable in js
page_name
Every page in PrestaShop has a unique value of page_name smarty variable.
This variable's value can be fetched through the following code in any controller:
$this->context->smarty->tpl_vars['page_name']->value
You can add a hook (i.e. hookHeader) and then add a condition in that hook for every page where you want to add the script.

Dynamic title depending on page (DRUPAL 7)

Before I made the switch to Drupal (previously just static HTML), I had a div title in my header that changed depending on what page the user was on using the following code:
ABOUT PAGE
<?php
$title = "ABOUT US</span>";
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/includes/header.php";
include_once($path); ?>
The reason this worked, however, was because I was using static HTML... which means I had every page set to use its own Index.PHP, located at (for the About page, for example) public_HTML/about/index.php. Therefore, I could edit each page individually to my liking by editing its respective Index file...
Now, with Drupal.. instead of having so many Index.PHP files like I did before (which was messy IMO...), I want to have every page use the same page.tpl.php (with the exception of the front page, which uses page--front.tpl.php).
Can I somehow modify the above PHP code to display a different title using IF statements depending on what page the user is on?
For example... (I have no idea how to PHP code so this is just to give you experts an idea of what I would want..)
Ifpage=about, $title=About Us;
Ifpage=contact, $title=Contact Us;
Could this code all be in the same page.tpl.php?
Thank you so much!
Drupal 7 has a title field for each content type. Why don't you use that?
It shows by default and you can change it for every node.
It is this code in your template file.
<?php print render($title_prefix); ?>
<?php if ($title): ?>
<h1 class="title" id="page-title">
<?php print $title; ?>
</h1>
<?php endif; ?>
<?php print render($title_suffix); ?>
$title_prefix (array): An array containing additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
$title: The page title, for use in the actual HTML content.
$title_suffix (array): An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template.
See https://api.drupal.org/api/drupal/modules!system!page.tpl.php/7 for all the variables available in your page.tpl template file.
If you want to style one part different from the other you could use an extra field for it.
Or if you need to do something with the value (I wouldn't suggest this!!!).
switch ($title) {
case "About Us":
// Do something with the title
break;
case "Contact Us":
// Do something with the title
break;
case 2:
// Do something with the title
break;
}
Here's a simple approach:
Add a new field for the content type
Call it title2
Render the two fields
Use css to inline align them and add styling
Here was my solution since I am unable to position a Drupal-based title block right next to a non-Drupal based logo DIV..
I created a div called .headertitle and positioned/styled it how I want.
My header.php is an PHP include file which is called by each page and the headertitle has a PHP condition..
<?php if(empty($headertitle)) $headertitle = "ASK REAL QUESTIONS, <br><span class='white'>GET FREE ANSWERS.</span>";
echo $headertitle; ?>
That way, if no text is declared for the .headertitle, it takes the default form of "ASK REAL QUESTIONS, GET FREE ANSWERS."
...Now, I had to figure out a way to actually declare text for the .headertitle depending on what page I was on...
I did this by using a custom template for each page (node) by using this file.. "page--node--nodeid.tpl.php".
So, for my ABOUT US page, I created a tpl.php file called "Page--node--7.tpl.php".. for this page, the 7 is the nodeid which is easy to find.
Then, I added the following PHP code to declare text for the .headertitle specifically on the ABOUT US page which looks like this...
<?php $headertitle = "ABOUT<span class='white'>.US</span>"; include('includes/header.php'); ?>
DONE AND DONE.
I'll do that for each page. :)

Magento Add to Wishlist code not working

I am using this snippet of code to add a wishlist to my product view
<a onclick="setLocation('<?php echo $this->getAddToWishlistUrl($_product) ?>')"
class="buttons-wish" title="<?php echo $this->__('Add to Wishlist') ?>"></a>
<a onclick="setLocation('<?php echo $this->getAddToCompareUrl($_product) ?>')"
class="buttons-compare" title="<?php echo $this->__('Add to Compare') ?>"></a>
But for some reason it is not working.
I need help to resolve the issue
Try this one.
<?php echo $this->__('Add to Wishlist') ?>
<?php echo $this->__('Add to Compare') ?>
One problem I found with the wishlist in Magento 1.8 is to do with the new form_key parameter, maybe this is what's caused the problem for you.
Magento 1.8 introduces form keys (they may have existed prior to 1.8 in some form, but now they're everywhere). They are mandatory if you want any of your forms to do anything. Want to add to cart / wishlist / comparison list? Need a form key. Want to submit a contact form? Need a form key. Want to log in? Form key. Etc.
All the necessary core templates have been updated to include this key as a hidden input element - in my experience you just need to copy and paste this line from any of a dozen different places into any custom templates you have (somewhere inside the form element) and they'll be fine too.
So all's well - a further security enhancement / spam prevention feature, and easy enough to accommodate.
The problem is that $this->helper('wishlist')->getAddUrl($_product) generates a URL that also contains this form key, e.g. /wishlist/index/add/product/101/form_key/xyz which simply doesn't work. And in this case, by "doesn't work", I mean the "add to wishlist" button doesn't add anything to your wishlist, although it does still take you to your wishlist page.
Whether by accident or by design I'm not sure, but it seems that form_key doesn't work in the URL like most Magento parameters do. It has to be a standard HTTP variable e.g. an input in a form field or added to the query string in a URL like ?form_key=xyz.
On the product view at least, and I think on the list view as well, the wishlist button actually calls productAddToCartForm.submitLight(), which means the URL doesn't need the form key at all, since productAddToCartForm already contains it.
How to fix it? As with most things there are a number of ways. You could stop using $this->helper('wishlist')->getAddUrl($_product) and replace it with something like $this->getStoreUrl('wishlist/index/add/product/'.$_product->getId()) (I haven't tested that so use with caution) or you could override Mage_Wishlist_Helper_Data::getAddUrl which is how I chose to do it. That way affects all templates etc that try to use an "add to wishlist" url, which could be a good thing or a bad thing. I think good, in this case, but it's up to you.
I copied Mage/Wishlist/Helper/Data.php from app/code/core to app/code/local and changed:
public function getAddUrl($item)
{
return $this->getAddUrlWithParams($item);
}
to:
public function getAddUrl($item)
{
$productId = null;
if ($item instanceof Mage_Catalog_Model_Product) {
$productId = $item->getEntityId();
}
if ($item instanceof Mage_Wishlist_Model_Item) {
$productId = $item->getProductId();
}
if ($productId) {
$params = array('product' => $productId);
return $this->_getUrlStore($item)->getUrl('wishlist/index/add', $params);
}
return false;
}
...which is simply a copy of the getAddUrlWithParams function with the "params" hard-coded to just the product id.
Check in the backend System->Configuration->Advanced->Advanced->Disable Modules Output
Mage_Wishlist is enabled or not.
I have faced a similar issue. Click on "Add to wishlist" and the page gets redirected to my favorites page with the below mentioned error message.
We can't add the item to Wish List right now: Cannot add product without stock to wishlist..
Solution: There is no issue with wishlist functionality. By default, Magento 2 ships with the wishlist functionality enabled. In our case, we were using multiple custom sources. You can check this out by visiting
Admin-> stores-> sources (if you see apart from the default source)
If you wish to disable the default source.
Admin -> Stores -> Configuration -> Catalog -> Inventory -> Product stock options -> Set the manage stock = NO
refer https://docs.magento.com/user-guide/catalog/inventory.html

Magento bundle dropdown need to display out of stock

In a bundle product page, I need to display if a product in the bundle is out of stock. Currently, the product is simply not appearing in the dropdown. I've looked at the "select.phtml" file and found at the beginning that this line of code get the option value for the dropdown :
<?php $_selections = $_option->getSelections(); ?>
Unfortunately, this doesn't fetch "out of stock" items. So, is there a way to include these items?
Thank you.
Hoping this can help someone. After searching for hours, finally found the line that was causing the problem inside app/code/core/Mage/Bundle/Block/View/Type/Bundle.php
You need to change this line
$this->_options = $optionCollection->appendSelections($selectionCollection, false,
Mage::helper('catalog/product')->getSkipSaleableCheck()
);
to this
$this->_options = $optionCollection->appendSelections($selectionCollection, false,
true
//Mage::helper('catalog/product')->getSkipSaleableCheck()
);
Building on SimCity's answer, rather than extending/overwriting the block, you can do the following. I have added this code to the top of bundle/catalog/product/view/type/bundle/options.phtml
// Get the current value of SkipSaleableCheck
<?php $skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck() ?>
// Overwrite this value with a 'true' value
<?php Mage::helper('catalog/product')->setSkipSaleableCheck(true) ?>
You can then reset this value at the bottom of the same file using the following code:
<?php Mage::helper('catalog/product')->setSkipSaleableCheck($skipSaleableCheck) ?>
This method provides the same result without having to overwrite core Magento blocks.
In Magento 1.8.1 you find the file in app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle.php
Be aware of making changes in the core will get you site no good for updates. Make a copy of your file to your local directory.

How can add tracking code (tradetracker and daisycon) on thank you page

I have a task, I did research but I still cannot be done.
I am using OpenCart. And I have to add code tracking (from tradetracker and daisycon) to thank you page.
How can I do it?
If you aren't too comfortable with writing your own extension and your tracking code is JavaScript or HTML you can place it straight into your template. You will find the template you need in:
/catalog/view/theme/default/template/common/success.php
The only problem is that this will now fire every time the page loads. Any success goes to this template.
To fix this you need to go into the controller and make a small addition.
Find:
if (isset($this->session->data['order_id'])) {
Add a new line below reading:
$this->data['enable_tracking'] = TRUE;
Then back in the template before simply add an if statement round the tracking code you have added like so:
<?php if($enable_tracking === TRUE){ ?>
Delete this line and replace with tracking code
<?php } ?>
That should solve your problem.

Categories