Hello everybody,
A few days ago I asked how to add the "Add to cart button" to the pricelist.
While waiting for an answer a friend of mine begun to try do it, as you'll see we are not a PHP specialists but he said this must be a copy/paste matter.
So he did :
in
/includes/languages/english/extra_definitions/pricelist.php
he added
Code:
define('TABLE_HEADING_ADDTOCART', 'Add to cart');
at the end just before the last ?>
in
/includes/modules/pages/pricelist/header_php.php
near line 119
Code:
after
define('TEXT_PL_HEADER_LOGO', $pl_profile);
he added
eval('$pl_profile = TABLE_HEADING_ADDTOCART_' . PL_PROFILE . ';');
define('TABLE_HEADING_ADDTOCART', $pl_profile);
near line 203
Code:
After
if (PL_SHOW_SOH == 'true') {
$colspan++;
he added
$colspan++;
near line 523
Code:
after
if (PL_SHOW_TAX_FREE == 'true') {
$columnsHeader .= '<td class="prcPL">' . TABLE_HEADING_PRICE_EX . PL_CURR_SYMBOL . '</td>' . "\n";
he added
$columnsHeader .= '<td>'. TABLE_HEADING_ADDTOCART . '</td>' . "\n";
And finally near line 610
Code:
after
if (PL_SHOW_TAX_FREE == 'true') {
$prodRow .= '<td class="' . $price_class . '">' . $products_price_ex . '</td>' . "\n";
}
he added
$display_qty = (($flag_show_product_info_in_cart_qty == 1 and $_SESSION['cart']->in_cart($products_id)) ? '<p>' . PRODUCTS_ORDER_QTY_TEXT_IN_CART . $_SESSION['cart']->get_quantity($products_id) . '</p>' : '');
// show the quantity box
$prodRow .='<td>' . zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($products_id), zen_get_all_get_params(array('action')) . 'action=add_product'), 'post', 'enctype="multipart/form-data" target="_Cartpage " class="AddButtonBox"') . "\n" . $the_button = PRODUCTS_ORDER_QTY_TEXT . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($products_id)) . '" maxlength="6" size="4" /><br />' . zen_get_products_quantity_min_units_display((int)$products_id) . '<br />' . zen_draw_hidden_field('products_id', (int)$products_id) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT). '</form></td>';
And all this works, you get an "Add to cart button" for every product. when you clic on it, the cart is built in a new window or new tab (depends on the browser).
BUT ! I tried to make it a bit cleaner and to go as far as I can to give the pricelist author clean files so that he can validate this modification. I tried to add a confirguration key in the database and to act regarding this key.
The key I added is PL_SHOW_ADDTOCART_BUTTON
Here is the SQL code
Code:
INSERT INTO `configuration` ( `configuration_title` , `configuration_key` , `configuration_value` , `configuration_description` , `configuration_group_id` , `sort_order` , `last_modified` , `date_added` , `use_function` , `set_function` )
VALUES (
'Show Add to cart button', 'PL_SHOW_ADDTOCART_BUTTON', 'true', 'Defines if the Add to cart button is visible or not.', '33', '210', NULL , '0001-01-01 00:00:00', NULL , 'zen_cfg_select_option(array(''true'', ''false''),'
), (
NULL , '', '', '', '', '0', NULL , NULL , '0001-01-01 00:00:00', NULL , ''
I wrapped the above modifications around "if{}" but, I don't see the new key in admin, nor the mod works. I must have an eval problem on my config key but I don't see where.
Here are the final modifications in
/includes/modules/pages/pricelist/header_php.php
line 119
Code:
eval('$pl_profile = TABLE_HEADING_ADDTOCART_' . PL_PROFILE . ';');
define('TABLE_HEADING_ADDTOCART', $pl_profile);
eval('$pl_profile = PL_SHOW_ADDTOCART_BUTTON_' . PL_PROFILE . ';');
define('PL_SHOW_ADDTOCART_BUTTON', $pl_profile);
line 204
Code:
if (PL_SHOW_ADDTOCART_BUTTON == 'true') {
$colspan++;
}
line 523
Code:
if (PL_SHOW_ADDTOCART_BUTTON == 'true') {
$columnsHeader .= '<td>'. TABLE_HEADING_ADDTOCART . '</td>' . "\n";
}
line 610
Code:
if (PL_SHOW_ADDTOCART_BUTTON == 'true') {
$display_qty = (($flag_show_product_info_in_cart_qty == 1 and $_SESSION['cart']->in_cart($products_id)) ? '<p>' . PRODUCTS_ORDER_QTY_TEXT_IN_CART . $_SESSION['cart']->get_quantity($products_id) . '</p>' : '');
// show the quantity box
$prodRow .='<td>' . zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($products_id), zen_get_all_get_params(array('action')) . 'action=add_product'), 'post', 'enctype="multipart/form-data" target="_Cartpage " class="AddButtonBox"') . "\n" . $the_button = PRODUCTS_ORDER_QTY_TEXT . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($products_id)) . '" maxlength="6" size="4" /><br />' . zen_get_products_quantity_min_units_display((int)$products_id) . '<br />' . zen_draw_hidden_field('products_id', (int)$products_id) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT). '</form></td>';
}
If any PHP guru could take a look at this and find the bug it would be very cool.
Thanks for help
Regards
Hubert
Here are the modified files.
Bookmarks