Display chosen quantity in Product

lasha

Avatar: lasha

2014-11-26 20:13

i want to display chosen quantity when i view products. For example i have 2 apple in my basket. i want when i view this apple's page see that i've already chosen 2. i hope u'll understand

» Quick.Cart v6.x

L. Andghuladze

boboo

Avatar: boboo

2014-11-27 05:47

Nothing easier than this :-)

put a new function into /core/products.php

public function countProductInBasket($iProduct){
 
$oFFS=FlatFilesSerialize::getInstance();
 
$iBasket=$_SESSION['iCustomer'.LANGUAGE];
 
$aBasket=$oFFS->getData(DB_ORDERS_TEMP); // assign file with basket data
 
if(isset($aBasket[$iBasket][$iProduct]['iQuantity'])&&$aBasket[$iBasket][$iProduct]['iQuantity']>0// if there is something with customer_id and just viewed product
  
return $aBasket[$iBasket][$iProduct]['iQuantity']; // return the basket quantity of this product
}



then in /templates/default/product.php
under:

if( isset( $aData['sAvailable'] ) ){?>
 <div id="available"><?php echo $aData['sAvailable']; ?></div><?php
}


add:

$iInBasket=$oProduct->countProductInBasket($iProduct);
if(
is_numeric($iInBasket)&&$iInBasket>0){
 echo 
'there '.(($iInBasket==1)?' is':' are').' already '.$iInBasket.(($iInBasket==1)?' piece':' pieces').' in basket';
 
// we check here the count of product in basket and depending on it (1 or more) we set singular ("is", "piece") or plural ("are", "pieces")
}


The words: "there are/is already ... piece/s in basket" you should fit to languages database.
That's all

boboo :-)

lasha

Avatar: lasha

2014-11-27 14:02

bobo thank you very much!

L. Andghuladze

lasha

Avatar: lasha

2014-11-27 20:47

boboo it works inside product's page but i also want to work on category page. can u help? :(

L. Andghuladze

boboo

Avatar: boboo

2014-11-28 19:04

Can You wait till tuesday? I'm right now on a business trip and don't have local server on my laptop. I have already the solution in my head (driving 1000 km gives enough time to think :-) )

boboo ;-)

lasha

Avatar: lasha

2014-11-28 20:46

of course i can. thank you very much again ! :)

L. Andghuladze

boboo

Avatar: boboo

2014-12-02 16:39

OK, we do it another way, we make it new.
1. Cancel the changes I wrote above;
2. /core/orders.php -> find function generateBasket()
3. In this function under:

$_SESSION['fOrderSummary'.LANGUAGE] = null;


add:

$_SESSION['iProductQuantity'.LANGUAGE]=null;


and under:

$_SESSION['fOrderSummary'.LANGUAGE]  += ( $aData['fPrice'] * $aData['iQuantity'] );


add:

$_SESSION['iProductQuantity'.LANGUAGE][$iProduct]=$aData['iQuantity'];


4. in the same file -> find function addOrder($aForm)
5. Under:

$_SESSION['fOrderSummary'.LANGUAGE] = null;


add:

$_SESSION['iProductQuantity'.LANGUAGE]=null;


6. file /templates/default/product.php
under:

if( isset( $aData['sAvailable'] ) ){?>
 <div id="available"><?php echo $aData['sAvailable']; ?></div><?php
}


add:

if(isset($_SESSION['iProductQuantity'.LANGUAGE][$aData['iProduct']])&&is_numeric($_SESSION['iProductQuantity'.LANGUAGE][$aData['iProduct']])&&$_SESSION['iProductQuantity'.LANGUAGE][$aData['iProduct']]>0){
 echo 
'there '.(($_SESSION['iProductQuantity'.LANGUAGE][$aData['iProduct']]==1)?' is':' are').' already '.$_SESSION['iProductQuantity'.LANGUAGE][$aData['iProduct']].(($_SESSION['iProductQuantity'.LANGUAGE][$aData['iProduct']]==1)?' piece':' pieces').' in basket';
}


7. file /core/products.php -> find function listProducts( $iPage, $iList = null, $aProducts = null )
8. under:

if( isset( $sBasketPage ) ){


add:

$sProductsInBasket=null;
if(isset(
$_SESSION['iProductQuantity'.LANGUAGE][$aData['iProduct']])&&is_numeric($_SESSION['iProductQuantity'.LANGUAGE][$aData['iProduct']])&&$_SESSION['iProductQuantity'.LANGUAGE][$aData['iProduct']]>0){
 
$sProductsInBasket='there '.(($_SESSION['iProductQuantity'.LANGUAGE][$aData['iProduct']]==1)?' is':' are').' already '.$_SESSION['iProductQuantity'.LANGUAGE][$aData['iProduct']].(($_SESSION['iProductQuantity'.LANGUAGE][$aData['iProduct']]==1)?' piece':' pieces').' in basket';
}



Of course You should format and make it nice, but I hope You can speak "CSS" and a bit "HTML" ;-)

boboo :-)

lasha

Avatar: lasha

2014-12-02 23:47

i know HTML/CSS. Thank you very much again. I've seen your posts and they are adorable :)

L. Andghuladze

Back to top
about us | contact