Add to cart button in osCommerce keeps redirecting back to product page - oscommerce

I have an ebook item in osCommerce that includes product attributes. When I click the Add to Cart button from the index page it should go directly to the shopping_cart.php page. However, it only keeps redirecting the customer back to the product_info.php page.
Why is it doing that?

If the product has attributes osCommerce expects that you select one of them before adding the product to the cart. That's why it is redirecting you to the product detail page.

try this code:
find if ($col === 0) {$new_prods_content .= '';} (around line 29)
below add this code:
$new_prods_content .= '<td width="30%" align="center" valign="top">
<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' .
$new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES .
$new_products['products_image'], $new_products['products_name'],
SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br /><a href="' .
tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' .
$new_products['products_id']) . '">' . $new_products['products_name'] .
'</a><br />' . $currencies->display_price($new_products['products_price'],
tep_get_tax_rate($new_products['products_tax_class_id'])) .
'&nbsp&nbsp&nbsp' . tep_draw_button(IMAGE_BUTTON_IN_CART, null ,
tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) .
'action=buy_now&products_id=' . $new_products['products_id'])) .'</td>';
i have added this code for new products in index.php page and when customer clicks add to cart button, it will add the item to cart and show shopping_cart.php page.

Related

Removing one item from opencart cart removes everything

My client is using an Opencart v2.1.0.2. The problem is when I remove a single item from the cart, all other items also gets removed. Yes, it's using a custom template and here's the line that calls for the delete function:
<td class="text-center"><button type="button" onclick="cart.remove('<?php echo $product['cart_id']; ?>');" title="<?php echo $button_remove; ?>" class="btn btn-danger btn-xs"><i class="fa fa-times"></i></button></td>
I also need to find out what js file is being called when this button is clicked. If it'll help, this I think this is the function from the cart.php library that opencart runs when deleting an item from the cart:
public function remove($cart_id) {
$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart_id . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
}
DELETE FROM
removes everything. It's missing the product id of what it's trying to remove.
WHERE only specifies: cart_id, customer_id and session_id - so this query removes everything matching that criteria. It doesn't hone in on a specific product, so it'll take them all.
Without knowing what variable it uses for the product ID, a proper query would be something like:
public function remove($cart_id) {
$this->db->query("DELETE '".(int)$this->request->post['product_id']."' FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart_id . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
}
(int)$this->request->get['product_id'] being the $_GET request for most product id calls.
Another instance could be:
(int)$this->request->post['product_id'] for a $_POST call
The template may also do something like $product_id so check what variable its using if the post/get doesn't work.
Once you got the query tightened up, the javascript button only specifies a cart id (not a product). Get your product ID in there if you want my example to work. You'll need to pass both the product_id and cart_id; else, without cart_id, if other shoppers have the same item at the same time, one person removing it would remove for them all.

accessing specific page with some criteria in opencart

I have a specific information page (page id is 12) and from admin panel i have assigned this page ID to particular product. For example, Information-id 12 is assigned to to Product1. When a user buys that product, and when the order status is set to 'Complete', user should have access to that page(information-id). I mean , to access this page, user should buy that product and order status is to be complete and user should logged in.
I am not getting how to do it. In order.tpl, i tried doing like this, but if i copy the URL and paste , it can be accessible without logging in.
here is my order_list.tpl
$end_date= date('Y-m-d', strtotime($start_date. ' + '.$date1. 'days'));
echo date('d/m/Y',strtotime($end_date));
?></td>
</tr>
<tr>
<td class="history">Product Name</td>
<?php $today = date('Y-m-d'); ?>
<?php if(($order['status']='Complete') AND ($today > $end_date)) { ?>
<td><strong><h4><font color="#FF0000">Either Your Course date is Expired or Order is not completed!!</font></h4></strong> </td>
<?php }
else { ?>
<td><strong><?php echo $order['pname']; ?></strong></td>
<?php } ?>
</tr>
Here i am also checking the expiry date, which am capturing through admin.
If i put customer_islogged(), in information.php(controller), i cannot access any other pages.
Create a function where you can pass list of products, any of that needs to be purchased to access that particular page
//catalog/model/account/order.php
public function checkForAccess($product_id_list){
$exists = false;
$query = $this->db->query("SELECT product_id FROM ".DB_PREFIX."order o LEFT JOIN ".DB_PREFIX."order_product op ON (o.order_id=op.order_id) WHERE o.order_status_id=5 AND o.customer_id = '" . (int)$this->customer->getId() ."'");
foreach($query->rows as $product){
if(in_array($product['product_id'],$product_id_list)){
$exists = true;
break;
}
}
return $exists;
}
Now in that particular page you can check if the customer has completed purchased or not
$this->load->model('account/order');
//Eg Customer will have access who have purchased product 20 and 22
$product_list = array(20,22);
$results = $this->model_account_order->checkForAccess($product_list);
if(!$results){
//where to redirect if not valid
$this->response->redirect($this->url->link('common/home'));
}

Moving "Product Options" Below Description Tab OpenCart

Haloo guys, I'm new here , i have a problem about template,
I want move this product options
http://i.stack.imgur.com/6BK4r.png
to bottom of Description tab .
Before, i can move it , but i had a problem , when i moved the product options Below Description Tab, when all required fields filled , then i push button "add to cart" , it said all required fields is Required!
Please help me, Thank you.
http://pastebin.com/rXPZCYBx
its the product page,
the product option page start from here
<div class="options push-<?php echo $this->journal2->settings->get('product_page_options_push_select'); ?>">
i make it back to normal

Database execution with Opencart

I am using this module which allows me to run a simple blog / news feed in OC which does what I need apart from one thing, I need to display the first 4 articles on the homepage.
I have got the following so far:
<?php
$sql = "SELECT * FROM " . DB_PREFIX . "blog b LEFT JOIN " . DB_PREFIX . "blog_description bd ON (b.blog_id = bd.blog_id) WHERE b.status = 1 AND b.date <= NOW() AND bd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
$query = $this->db->query($sql);
$blogs = array();
?>
<div class="box" id="news">
<div class="title">
<p>Latest News</p>
</div>
<div class="content">
<?php
foreach($query->rows as $result){
$blogs[] = $result;
}
?>
</div>
</div>
I have been developing OC templates for a while but modules are a whole new ball game for me, any help would be appreciated
First of all You should learn and understand how the MVC (or whatever it tends to be) is implemented in OpenCart - we have controllers, models and view templates.
Your approach is mixing all the controller and model part into a view template which is completely wrong.
So what should go where:
SQL query should go into the model
A new method for retrieving the data from the model and preparing it for the view template should go into the controller
Only HTML markup should be present in the view template
Let's say the extension You have downloaded has a controller here: catalog/controller/information/news.php - You should extend it's index() (or other appropriate) method (or even create a new one if needed) so that it calls the news model where You place Your new method getLastFourArticles() which should look like:
public function getLastFourArticles() {
$sql = "
SELECT *
FROM " . DB_PREFIX . "blog b
LEFT JOIN " . DB_PREFIX . "blog_description bd ON b.blog_id = bd.blog_id
WHERE b.status = 1
AND b.date <= NOW()
AND bd.language_id = " . (int)$this->config->get('config_language_id') . "
ORDER BY b.date DESC
LIMIT 4";
return $this->db->query($sql);
}
ORDER BY part will sort the blog entries from the newest to the latest and the LIMIT 4 part will make sure we only receive 4 rows maximally.
Now in the controller You should do something like:
$this->data['latest_entries'] = $this->model_information_news->getLastFourArticles();
while expecting the model to be catalog/model/information/news.php and that it is loaded ($this->load->model('information/news');).
Now in Your template only this part is needed:
<div class="box" id="news">
<div class="title">
<p>Latest News</p>
</div>
<div class="content">
<?php foreach($latest_entries as $entry) { ?>
<span class="date"><?php echo $entry['date']; ?></span>
<span class="entry"><?php echo $entry['text']; ?></span>
<?php } ?>
</div>
</div>
Keep in mind this is only instruction-like answer and You should pass in the right names and variables (and indices for the blog entry in the template).

How to publish youtube video to wall of facebook

I wanted to publish youtube video to wall of facebook.Does any one know ,how to do that.If yes,let me know that.
well i use involver
http://www.involver.com/
to publish vids from youtube to my fb page but it doesn't work on personal facebook wall
you can press the share button under the youtube video and share it to facebook and it will be published on your wall, you can also copy the link and past it on facebook wall
Basically, this page is a very good start. It explains how to publish using GraphAPI.
You'll need an app ( this page ) and you'll need to :
Get the app linked to your account with permissions ( publish_stream for publishing on a User's wall ) echoing some javascript to reload the page to facebook with a redirect_uri to your app or your web page.
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=publish_stream";
echo("<script>top.location.href='" . $dialog_url . "'</script>");
Get the token via
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$access_token = file_get_contents($token_url);
Then you'll need to send a post with enctype="multipart/form-data" to https://graph-video.facebook.com/me/videos? with the following elements:
token
description
title
file ( as a multipart upload stream )
using a form like:
<form enctype="multipart/form-data" action="<?php echo $my_url ?>" method="POST">
<input type="file" name="file>
<input type="submit">
</form>
The main drawback is that after you successfully uploaded ( or not ) you'll have a plain json with either the error code or the Object Graph ID of the newly created element. I haven't sorted out yet how to overcome that. I'll try CURL out.