Added a product code, want it listed in orders

KiralyVlad

No avatar

2006-11-11 16:35

Hi... I've managed to add a unique Product Code for each product.... I've edited the templates, and core/products.php , products-ff.php, products-admin.php
I can add the product code in the admin panel, it also shows up in the products list in the admin panel, and also on my shops pages next to the products....

But when I try adding "$aList[sProductCode]" in the ordersbasket.tpl template... it won't show the products code... I tried with an "include products.php;" in the core/orders.php file but still no luck.... Any help apreciated.

KiralyVlad

No avatar

2006-11-11 21:21

Treewood, Claps ?! Any ideas please ?

KiralyVlad

No avatar

2006-11-12 18:02

Help, help, help...

KiralyVlad

No avatar

2006-11-13 14:48

Seems this is way too much for and ordinary "helper", BUT, I would really need some help, or some pinpoints.

Claps

Avatar: Claps

2006-11-13 15:43

KiralyVlad - maybe you can send me (or us :)) a zip with files you modified and some info, so I can create your context, and I can Take a look and maybe solve the problem.

KiralyVlad

No avatar

2006-11-13 18:55

Claps, here is my topic:

http://opensolution.org/Quick.Cart/forum/?p=readTopic&nr=3166

It's just the last post... the other two are incomplete, maybe someone capable could delete them.... (I've posted 2 posts, and the first one got deleted, so I merged all of it in a single post - the last one)

You will find there every step I've done... I could also create a .zip if needed. Thank you for your time.

Claps

Avatar: Claps

2006-11-14 10:53

KiralyVlad - it's because of the way the script handles orders. You write productCode in products DB, but the orders are dealing with products in order_products DB. Check listBasket(...) function in core/orders.php and I think you'll figure out.

KiralyVlad

No avatar

2006-11-14 13:31

Well... I've got the point, I guess I need to find where $aList is defined, add my variable there, then I need to make it take the value out of db/products.php, then return to core/orders.php and modify, as well as the template...

But it seems I`m stuck... I need more guidance, if you please. Thank you.

KiralyVlad

No avatar

2006-11-14 17:58

Well.... I`m half way there.... this is what I've done:

core/orders-ff.php

if( !function_exists( 'dbAddOrderProduct' ) ){
/**
* Add product to basket
* @return void
* @param array $aProduct
* @param int $iQuantity
* @param int $iOrder
*/
function dbAddOrderProduct( $aProduct, $iQuantity, $iOrder ){
global $oFF;
$iElement = throwLastId( DB_ORDERS_PRODUCTS, 0 ) + 1;
$oFF->setRow( Array( $iElement, $iOrder, $aProduct['iProduct'], $iQuantity, $aProduct['fPrice'], $aProduct['sName'] ) );
$oFF->addToFile( DB_ORDERS_PRODUCTS, 'end' );

Changed to:

if( !function_exists( 'dbAddOrderProduct' ) ){
/**
* Add product to basket
* @return void
* @param array $aProduct
* @param int $iQuantity
* @param int $iOrder
*/
function dbAddOrderProduct( $aProduct, $iQuantity, $iOrder ){
global $oFF;
$iElement = throwLastId( DB_ORDERS_PRODUCTS, 0 ) + 1;
$oFF->setRow( Array( $iElement, $iOrder, $aProduct['iProduct'], $iQuantity, $aProduct['fPrice'], $aProduct['sName'], $aProduct['sProductCode'] ) );
$oFF->addToFile( DB_ORDERS_PRODUCTS, 'end' );

and:

if( !function_exists( 'dbSaveOrderProduct' ) ){
/**
* Save product to file
* @return void
* @param array $aData
*/
function dbSaveOrderProduct( $aData ){
global $oFF;
$oFF->setRow( Array( $aData[0], $aData[1], $aData[2], $aData[3], $aData[4], $aData[5] ) );
$oFF->changeInFile( DB_ORDERS_PRODUCTS, $aData[0], 0 );
} // end function dbSaveOrderProduct

changed to:

if( !function_exists( 'dbSaveOrderProduct' ) ){
/**
* Save product to file
* @return void
* @param array $aData
*/
function dbSaveOrderProduct( $aData ){
global $oFF;
$oFF->setRow( Array( $aData[0], $aData[1], $aData[2], $aData[3], $aData[4], $aData[5], $aData[6] ) );
$oFF->changeInFile( DB_ORDERS_PRODUCTS, $aData[0], 0 );
} // end function dbSaveOrderProduct


then in core/orders.php in the listBasket function:

for( $i = 0; $i < $iCount; $i++ ){
list( $aList['iElement'], $aList['iOrder'], $aList['iProduct'], $aList['iQuantity'], $aList['fPrice'], $aList['sProduct'] ) = $aData[$i];

changed to:

for( $i = 0; $i < $iCount; $i++ ){
list( $aList['iElement'], $aList['iOrder'], $aList['iProduct'], $aList['iQuantity'], $aList['fPrice'], $aList['sProduct'] , $aList['sProductCode']) = $aData[$i];

edited the orders_basket.tpl / orders_delivery.tpl

And the product code eventually shows ! but, only after I add the product to the cart.... when I continue to orders_delivery.tpl or when I refresh the orders_basket.tpl page, the product code disappears...

KiralyVlad

No avatar

2006-11-14 18:36

Ok I've done it .... I only had to change this in the core/orders-ff.php:

function dbSaveOrderProducts( $aElements ){
$aFile = file( DB_ORDERS_PRODUCTS );
$rFile = fopen( DB_ORDERS_PRODUCTS, 'w' );
$iCount = count( $aFile );

for( $i = 0; $i < $iCount; $i++ ){
if( $i > 0 ){
$aFile[$i] = rtrim( $aFile[$i] );
$aExp = explode( '$', $aFile[$i] );
if( isset( $aElements[$aExp[0]] ) && $aElements[$aExp[0]] >= 1 )
$aFile[$i] = $aExp[0].'$'.$aExp[1].'$'.$aExp[2].'$'.sprintf( '%01.0f', $aElements[$aExp[0]] ).'$'.$aExp[4].'$'.$aExp[5].'$'."\n";
else
$aFile[$i] .= "\n";
}

changed to this:

function dbSaveOrderProducts( $aElements ){
$aFile = file( DB_ORDERS_PRODUCTS );
$rFile = fopen( DB_ORDERS_PRODUCTS, 'w' );
$iCount = count( $aFile );

for( $i = 0; $i < $iCount; $i++ ){
if( $i > 0 ){
$aFile[$i] = rtrim( $aFile[$i] );
$aExp = explode( '$', $aFile[$i] );
if( isset( $aElements[$aExp[0]] ) && $aElements[$aExp[0]] >= 1 )
$aFile[$i] = $aExp[0].'$'.$aExp[1].'$'.$aExp[2].'$'.sprintf( '%01.0f', $aElements[$aExp[0]] ).'$'.$aExp[4].'$'.$aExp[5].'$'.$aExp[5].'$'."\n";
else
$aFile[$i] .= "\n";
}


Thank you Claps

KiralyVlad

No avatar

2006-11-16 00:44

Well.... this was the lazy (and unexperienced) way to do it.... At the moment I`m just happy I managed to do it on my own.... But... I made it save the product code in the db/orders_products.php..... so the product code is saved in two different places.... I don't know how inter-dependant are these two.... Could anyone help me make the orders.php take the $sProductCode from the actual db/products.php file ?

Thank you.

Back to top
about us | contact