Quantity in Opencart - php

Dear stackoverflow code experts. I have a query relating to opencart stock.
The frontend product page has option of displaying Stock, either in terms of availability (Available or Out of Stock) or in terms of quantity in actual numbers.
Is it possible to display it in some other way? eg. I want that if the stock quantity is less than or equal to 5, then it should display quantity, else display the text: Available.
Or in a more sophisticated manner, if product quantity is greater than 5 or zero, then display text, else display quantity in number.
I understand it may have to do something with ../catalog/controller/product/product.php file.
I am not an expert in coding. Please help me.
Thank you.

It's simple.
First set "display stock" to Yes
admin panel>system>setting>options set display stock to "YES"
now
//catalog>controller>product>product.php
Find (around line 282)
if ($product_info['quantity'] <= 0) {
$this->data['stock'] = $product_info['stock_status'];
} elseif ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];
} else {
$this->data['stock'] = $this->language->get('text_instock');
}
Replace With
if ($product_info['quantity'] <= 0) {
$this->data['stock'] = $product_info['stock_status'];
} elseif ($this->config->get('config_stock_display') && $product_info['quantity'] <= 5) {
$this->data['stock'] = $product_info['quantity'];
} else {
$this->data['stock'] = $this->language->get('text_instock');
}
Hope this helps

Edit the file catalog/controller/product/category.php
Step : 1
Find the code:
if ($this->config->get('config_review_status')) {
$rating = (int)$result['rating'];
} else {
$rating = false;
}
Add the following just below the above code :
if ($result['quantity'] <= 0) {
$rstock = $result['stock_status'];
} elseif ($this->config->get('config_stock_display')) {
$rstock = "Stoc: " . $result['quantity'];
} else {
$rstock = "In stoc";
}
Step : 2
Find :
'thumb' => $image,
Add the following just after the above line
'stoc' => $rstock,
Step 3
Edit the file catalog/view/theme/yourtheme/template/product/category.tpl
Find :
<div class="cart">
Add the following :
<?php echo $product['stoc']; ?>
And now the stock will appear for products in category page.
You can do the same for search (the files would be search.php and search.tpl - in the same folders as the category)
You can see a more detailed tutorial at :
http://www.aleixcortadellas.com/main/2009/09/09/742/
http://forum.opencart.com/viewtopic.php?t=27137
http://forum.opencart.com/viewtopic.php?t=66506
All of the above uses the same idea, but implemented in different ways. But this should help you solve your problem.
Hope this helps.

Related

Add the same idProduct to SESSION in cart php

I´m making a cart in php that get the data of the products from a MySQL Database.
The problem is: I can´t add the same product to the SESSION.
I need that, because the user may want one product with a picture and another one with another picture;
I need that so much.
This is the code I'm using to add the item to the cart:
if(isset($_GET['action'])){
//ADD TO THE CART
if($_GET['action'] == 'add'){
$id = intval($_GET['idProduct']);
if(!isset($_SESSION['cart'][$id])){
$_SESSION['cart'][$id] = 1;
}else{
$_SESSION['cart'][$id] += 1;
}
}
//UPDATE CART
if($_GET['action'] == 'up'){
if(is_array($_POST['prod'])){
foreach($_POST['prod'] as $id => $qtd){
$id = intval($id);
$qtd = intval($qtd);
if(!empty($qtd) || $qtd <> 0){
$_SESSION['cart'][$id] = $qtd;
}else{
unset($_SESSION['cart'][$id]);
}
}
}
}
I don't know how to add the same product. I tried using an Array and getting the KEY from it, but I didn't know how to use it;

PHP If offer is rejected 3 times, remove div

I have a "offer" button that lets the user enter a price offer. If they enter 3 offers and all are rejected, I want the div to be removed.
if(isset($_POST['offer_form']) && !empty($_POST['offer_form'])){
if($offers === "1"){
if($_POST['offer_form'] >= $price_offer){
echo 'Accepted';
}else{
echo '<div class="offer_errors">Offer Rejected</div>';
}
}else{
echo '<div class="offer_errors">Sorry, no offers can be made</div>';
}
}
You can try to use Sessions
session_start();
$_SESSION['offer']=1;
Something like that.
to increment is do something like this:
session_start();
if(isset($_SESSION['offer']) && $_SESSION['offer'] != ''){
$offer = $_SESSION['offer'];
$offer += 1;
$_SESSION['offer'] = $offer;
}else{
$_SESSION['offer'] = 1;
}
Just get some ideas from this. I dont think this is ready for what you need. Just modify it suit your needs.

how to get stock status in opencart product page

I want to show
out of stock
on my product page and I change the status from admin and is updated in admin but on my product page there is also same
In Stock
and product page code is
if ($product_info['quantity'] <= 0) {
$this->data['stock'] = $product_info['stock_status'];
} elseif ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];
} else{
$this->data['stock'] = $this->language->get('text_instock');
}
and language page is
$_['text_outstock'] = 'Out of Stock';
Now what condition is used there?
As far as I understand your issue, you can set it directly in the Admin to show 'out of stock' message.
You need to set it both in the general settings AND in the invidividual product.
Currently, because you did not set your Admin settings correctly, $product_info['stock_status'] does not display 'out of stock'.
However, if you insist of modifying the code, you need to use the following:
if ($product_info['quantity'] <= 0) {
//out of stock message
$this->data['stock'] = $this->language->get('text_outstock');
} elseif ($this->config->get('config_stock_display')) {
//in stock, and displaying exact quantity
$this->data['stock'] = $product_info['quantity'];
} else{
//in stock, but just display a message not exact quantity
$this->data['stock'] = $this->language->get('text_instock');
}
Hope this helps!

Allow customers to buy out-of-stock items in OpenCart

I have been looking for a module to allow a client to be able to still purchase an item if the stock level is 0. Is this feature available in OpenCart 1.5.x?
I have set the product to 2-3 days, however on the site front-end it still shows the product as out of stock. Is there away to alert the client of the 2-3 day delay, and still allow the client to purchase?
First you need to change the function that prevents an out of stock item from going to checkout. Go to catalog/controller/checkout/checkout.php and change
public function index() {
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$this->redirect($this->url->link('checkout/cart'));
}
to
public function index() {
// Validate cart has products and has stock.
if (!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) {
$this->redirect($this->url->link('checkout/cart'));
}
I don't remember if it blocks you from adding it to the cart in the first place so let me know. Good luck David!
Update
To change "Out of Stock" on the product page, I have changed it myself with the settings in the store so if that isn't working for you then you can go into catalog/controller/product/product.php and where you see
if ($product_info['quantity'] <= 0) {
$this->data['stock'] = $product_info['stock_status'];
} elseif ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];
} else {
$this->data['stock'] = $this->language->get('text_instock');
}
Change to:
if ($product_info['quantity'] <= 0) {
$this->data['stock'] = "2-3 Days";
} elseif ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];
} else {
$this->data['stock'] = $this->language->get('text_instock');
}
Change the text within those brackets to whichever phrase works for you.
This is a feature built into OpenCart as standard. The setting should be on the "Option" tab in your settings page
First find
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
and replace with
if (1==1 || !$option_value['subtract'] || ($option_value['quantity'] > 0)) {

Magento - Display shoppingcart image instead of "My Cart" in Toplinks?

i am trying to display a shoppingcart image instead of the "My Cart"-Phrase. Above the shoppingcart image has just the number of items in the cart to appear.
To change the text one has to edit the mage/checkout/block/links.php and there this part:
public function addCartLink()
{
$parentBlock = $this->getParentBlock();
if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) {
$count = $this->getSummaryQty() ? $this->getSummaryQty()
: $this->helper('checkout/cart')->getSummaryCount();
if ($count == 1) {
$text = $this->__('My Cart (%s item)', $count);
} elseif ($count > 0) {
$text = $this->__('My Cart (%s items)', $count);
} else {
$text = $this->__('My Cart (0 items)');
}
to
public function addCartLink()
{
$parentBlock = $this->getParentBlock();
if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) {
$count = $this->getSummaryQty() ? $this->getSummaryQty()
: $this->helper('checkout/cart')->getSummaryCount();
if ($count == 1) {
$text = $this->__('</span></span>%s</span></span>', $count);
} elseif ($count > 0) {
$text = $this->__('<span><span>%s</span></span>', $count);
} else {
$text = $this->__('<span><span>0'</span></span>);
}
So, now the items number is showing inside/above the shopping cart image. Just as i wanted it to be. Problem is: By hoovering over the link it shows now the span span-tags before and after the item number.
Any idea how to change that link title there? Or maybe is there a even better way to display a shoppingcart image in the toplinks?
A little below the block you quoted in the Magento source, I see this line:
$parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart"');
Try providing different values for the two values that $text is given for - I bet one of them is the HTML of the link, and the other is the tooltip text. (You should probably use $this->__() for the new text as well, for consistency - though it's unlikely to have any effect, since what it does is allow Magento to translate that text to another language.) You could then have spans in the HTML version, while leaving them out of the tooltip.

Categories