AbanteCart Community

Shopping Cart Operations => Support => General Support => Topic started by: ygalbrami on June 01, 2013, 11:18:27 AM

Title: see the sku
Post by: ygalbrami on June 01, 2013, 11:18:27 AM
is there any way so i can see the sku next to product name?
i need this when buyer checkout in page: index.php?rt=checkout/confirm

i try a lot of option but i can make this happend,

please help me.
Title: Re: see the sku
Post by: abantecart on June 03, 2013, 07:59:27 AM
You need to change template to display the SKU and possibly you will need to add it in the controller to be passed to the view.
Title: Re: see the sku
Post by: ygalbrami on June 03, 2013, 08:30:51 AM
Can you please give me code to add or change? I want the code will be a code of a ante cart I don't want to use my code

Thanks
Title: Re: see the sku
Post by: abolabo on June 04, 2013, 08:04:07 AM
open file core/lib/cart.php... go to line 247 and add sku into array
Code: [Select]
$result = array(
        'product_id'   => $product_query['product_id'],
        'name'         => $product_query['name'],
        'model'        => $product_query['model'],
        'shipping'     => $product_query['shipping'],
        'option'       => $option_data,
        'download'     => $download_data,
        'quantity'     => $quantity,
        'minimum'      => $product_query['minimum'],
        'maximum'      => $product_query['maximum'],
        'stock'        => $stock,
        'price'        => ($price + $option_price),
        'total'        => ($price + $option_price) * $quantity,
        'tax_class_id' => $product_query['tax_class_id'],
        'weight'       => $product_query['weight'],
        'weight_class' => $product_query['weight_class'],
        'length'       => $product_query['length'],
        'width'        => $product_query['width'],
        'height'       => $product_query['height'],
        'length_class' => $product_query['length_class'],
        'ship_individually' => $product_query['ship_individually'],
        'shipping_price' => $product_query['shipping_price'],
        'free_shipping' => $product_query['free_shipping'],
        'sku' => $product_query['sku']
  );
Then open core/lib/order and add sku there (line 266):
Code: [Select]
    $product_data[] = array(
        'product_id' => $product['product_id'],
'name'       => $product['name'],
        'model'      => $product['model'],
        'option'     => $option_data,
'download'   => $product['download'],
'quantity'   => $product['quantity'],
'price'      => $product['price'],
'sku'        => $product['sku'],
        'total'      => $product['total'],
'tax'        => $this->tax->calcTotalTaxAmount($product['total'],$product['tax_class_id']),
'stock'      => $product['stock']);

now you can see sku on your template, i mean storefront/view/default_html5/template/pages/checkout/confirm.tpl ...or old default template
Title: Re: see the sku
Post by: ygalbrami on June 04, 2013, 04:11:01 PM
thank you so so much.
i have do it and this work.
i have try to make it work on other file, on this file in admin panel: admin\view\default\template\responses\sale\order_invoice.tpl

so when buyer will make an order i will go to the admin panel, i will press on print invoice and i will see the SKU

so i have add this code to the file: order_invoice.tpl

Code: [Select]
<?php echo $product['sku']; ?>
and i have added this code to this file: admin\controller\pages\sale\order.php

Code: [Select]
'sku'      => $order_product['sku'],
to the line: 354

what i am doing wrong?
and how to make this work?

Big Thanks
Title: Re: see the sku
Post by: abolabo on June 04, 2013, 04:40:04 PM
i think you try to edit wrong controller.
admin\view\default\template\responses\sale\order_invoice.tpl
and controller is "response" too   -    admin/controller/responses/sale/invoice.php

Title: Re: see the sku
Post by: ygalbrami on June 04, 2013, 05:12:03 PM
I have try this but its not working any idia why?

Title: Re: see the sku
Post by: ygalbrami on June 04, 2013, 06:40:45 PM
in the file: invoice.php

i make this change on the line: 138

Code: [Select]
$product_data[ ] = array(
'name'  => $product[ 'name' ],
'model' => $product[ 'model' ],
'sku'   => $product[ 'sku' ],
'option' => $option_data,
'quantity' => $product[ 'quantity' ],
'price' => $this->currency->format($product[ 'price' ], $order_info[ 'currency' ], $order_info[ 'value' ]),
'total' => $this->currency->format($product[ 'total' ], $order_info[ 'currency' ], $order_info[ 'value' ])
);

and in the file: order_invoice.tpl
i put this:
Code: [Select]
<?php echo $product['model'] .  $product['sku']; ?>in line: 72

this don't work what is wrong?
Title: Re: see the sku
Post by: abolabo on June 06, 2013, 07:08:36 AM
i digged into code and found that order data does not contain sku.. i can't give you quick solution right now.
Title: Re: see the sku
Post by: ygalbrami on June 06, 2013, 07:30:23 AM
Ok please when you will have this cost post it here I really need that code

Thank you so much in advance
Title: Re: see the sku
Post by: abantecart on June 06, 2013, 11:12:45 AM
There are 2 solutions but both require coding:

1. Based on the product details in the order, load product SKU and Attributes SKUs.
Need to change: Controllers, Models and template on admin side. Not visible to customers.

2. Add SKU details to the order table and display in order details screens.
Need to change: Admin Controllers, Models and template on admin side, order creation controller on storefront side. And finally alter order tables to add these details.


Title: Re: see the sku
Post by: ygalbrami on June 06, 2013, 11:17:30 AM
In few hours I will give you a code the join tables and give me the SKU but I want this code will be transformed to abantecart code and not custom code.
And yes I need that it will be invisible to user.
Title: Re: see the sku
Post by: ygalbrami on June 06, 2013, 05:14:57 PM
this is the code that work on the file:

Code: [Select]
$select_ab_order_products = mysql_query ("SELECT * FROM ab_order_products INNER JOIN ab_products ON ab_order_products.product_id = ab_products.product_id WHERE ab_order_products.order_id='$order_id'") or die ("can't select");
foreach ($products as $product) {
$get_row_product_id = mysql_fetch_array ($select_ab_order_products) ;

this code do the work but is not AbanteCart card, how can i put this so this will be like AbanteCart cart code and not custom code?

thanks
Title: Re: see the sku
Post by: abolabo on June 07, 2013, 04:01:02 AM
your code ignores sku that set to product option.
Title: Re: see the sku
Post by: ygalbrami on June 07, 2013, 06:34:40 AM
I make some change in my code so that is work very good

Code: [Select]
$connect_this = mysql_connect(DB_HOSTNAME,DB_DATABASE,DB_PASSWORD) or die("error connect");
$mysql_db = mysql_select_db("ismyvodc_mystore")or die("error db");
$get_orderid = $_GET['order_id'];
$select_ab_order_products = mysql_query("SELECT * FROM order_products INNER JOIN products ON order_products.product_id = products.product_id WHERE order_products.order_id='$get_orderid'") or die ("can't select");

and after this code:
Code: [Select]
<?php foreach ($order['product'] as $product) {i put my code:
Code: [Select]
$get_row_product_id = mysql_fetch_array($select_ab_order_products);
and i put this to see the sku:
Code: [Select]
<?php echo $get_row_product_id['sku']; ?>
but i need this code will be AbanteCart code.
if you can please help me with that?

i send you an image that show you the sku.

all the code i put in the file: order_invoice.tpl
Title: Re: see the sku
Post by: abolabo on June 07, 2013, 07:27:44 AM
i said about product options... not product sku.
Abantecart allow to set sku for option too.
For ex. you have product with name "shoes". Shoes have 2 options: size and color. For all combination of this properties merchant can set different values of sku. that's why changing of core is difficult right now.
You showed me your custom, partial, solution.
Why do you don't change method getOrderProducts() on file public_html/admin/model/sale/order.php ?
it used by sale/invoice.php controller.
FYI. you don't need to create new connection to database. Instance of db-class is already in memory.
you can do
Code: [Select]
$this->db->query($sql) in any controllers and models
or
Code: [Select]
$registry = Registry::getInstance()
$registry->get('db')->query(sql);
everywhere in code

But personally i prefer to create custom extension with hooks of controllers.. this approach saves your changes after cart upgrade.
Title: Re: see the sku
Post by: ygalbrami on June 07, 2013, 07:48:12 AM
thank you so much for this, this is want i need.

i have the code to select db
Code: [Select]
SELECT * FROM order_products INNER JOIN products ON order_products.product_id = products.product_id WHERE order_products.order_id='$get_orderid

can you show me how to put my code to this:
Code: [Select]
$this->db->query($sql)
thanks again very very much
Title: Re: see the sku
Post by: abolabo on June 07, 2013, 08:39:57 AM
$result = $this->db->query("SELECT * FROM order_products INNER JOIN products ON order_products.product_id = products.product_id WHERE order_products.order_id='".(int)$order_id."'" );
var_dump($result->rows); 
$result->rows - is array with all rows.
Title: Re: see the sku
Post by: ygalbrami on June 07, 2013, 10:10:54 AM
i put this on invoice.php

Code: [Select]
$result = $this->db->query("SELECT * FROM order_products INNER JOIN products ON order_products.product_id = products.product_id WHERE order_products.order_id='".(int)$order_id."'" );
 


foreach ($result->rows as $product) {
$product['sku'];

}

echo $product['sku'];

and i see the sku at the top of the page so it work

but when i put the line into: order_invoice.tpl - i don't see the sku why is that?
what i am doing wrong?
Code: [Select]
echo $product['sku'];

Title: Re: see the sku
Post by: abolabo on June 07, 2013, 10:24:29 AM
try to write

echo $orders['products']['sku'];

controller $this->data['orders'] become $orders variable inside tpl..
Title: Re: see the sku
Post by: ygalbrami on June 08, 2013, 02:47:22 PM
So sorry but its don't work.
I will use my code for this.

The best way I see to use a AbanteCart cart code is when users make an order it will put in do database the SKU then is no problem to get the data.