Откройте файл admin/includes/database_tables.php, найдите:
define('TABLE_CUSTOMERS_INFO', 'customers_info');
и после вставьте:
// Get 1 Free
define('TABLE_GET_1_FREE', 'get_1_free');
Откройте файл admin/includes/filenames.php, найдите:
define('FILENAME_GEO_ZONES', 'geo_zones.php');
и после вставьте:
// Get 1 Free
define('FILENAME_GET_1_FREE', 'get_1_free.php');
Откройте файл admin/includes/functions/general.php, найдите:
$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by products_name");
и замените на:
// start Get 1 Free
$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_status = '1' order by products_name");
// end Get 1 Free
Откройте файл admin/includes/boxes/catalog.php, найдите:
array(
'code' => FILENAME_PRODUCTS_EXPECTED,
'title' => BOX_CATALOG_PRODUCTS_EXPECTED,
'link' => tep_href_link(FILENAME_PRODUCTS_EXPECTED)
)
и замените на:
array(
'code' => FILENAME_PRODUCTS_EXPECTED,
'title' => BOX_CATALOG_PRODUCTS_EXPECTED,
'link' => tep_href_link(FILENAME_PRODUCTS_EXPECTED)
),
array(
'code' => FILENAME_GET_1_FREE,
'title' => BOX_CATALOG_GET_1_FREE,
'link' => tep_href_link(FILENAME_GET_1_FREE)
)
Откройте файл admin/includes/languages/russian.php, и добавьте в конце файла:
// Get 1 Free
define('BOX_CATALOG_GET_1_FREE', 'Один товар бесплатно');
Откройте файл admin/includes/languages/english.php, если есть, и добавьте в конце файла:
// Get 1 Free
define('BOX_CATALOG_GET_1_FREE', 'Get 1 Free');
Откройте файл checkout_process.php, найдите:
//------insert customer choosen option eof ----
$products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "n";
и после добавьте:
// start Get 1 free
// If this product qualifies for free product(s) add the free products
if (is_array ($free_product = $cart->get1free ($products_id))) {
// Update products_ordered (for bestsellers list)
// Comment out the next line if you don't want free products in the bestseller list
tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $free_product['quantity']) . " where products_id = '" . tep_get_prid($free_product['id']) . "'");
$sql_data_array = array('orders_id' => $insert_id,
'products_id' => $free_product['id'],
'products_model' => $free_product['model'],
'products_name' => $free_product['name'],
'products_price' => 0,
'final_price' => 0,
'products_tax' => '',
'products_quantity' => $free_product['quantity']
);
tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
$total_weight += ($free_product['quantity'] * $free_product['weight']);
}
// end Get 1 free
Откройте файл product_info.php, найдите:
<div class="page-header">
<h1 class="pull-right" itemprop="offers" itemscope itemtype="http://schema.org/Offer"><?php echo $products_price; ?></h1>
<h1><?php echo $products_name; ?></h1>
</div>
и перед ним добавьте:
<?php
// start Get 1 Free
// If this product qualifies for free product(s) display promotional text
$get_1_free_query = tep_db_query("select pd.products_name,
g1f.products_free_id,
g1f.products_free_quantity,
g1f.products_qualify_quantity,
g1f.get_1_free_expires_date
from " . TABLE_GET_1_FREE . " g1f,
" . TABLE_PRODUCTS_DESCRIPTION . " pd
where g1f.products_id = '" . (int)$product_info['products_id'] . "'
and pd.products_id = g1f. products_free_id
and pd.language_id = '" . (int)$languages_id . "'
and status = '1'"
);
if (tep_db_num_rows($get_1_free_query) > 0) {
$free_product = tep_db_fetch_array($get_1_free_query);
echo '<p class="alert alert-success">' . sprintf (TEXT_GET_1_FREE_PROMOTION, $free_product['products_qualify_quantity'], $product_info['products_name'], $free_product['products_free_quantity'], '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $free_product['products_free_id']). '" target="_blank">' . $free_product['products_name'] . '</a>');
if ($free_product['get_1_free_expires_date'] > date('Y-m-d H:i:s')) {
echo '<span class="small"><em>' . TEXT_OFFER_ENDS . ' ' . tep_date_long($free_product['get_1_free_expires_date']) . '</em></small>';
}
echo '</p>';
}
// end Get 1 Free
?>
<div class="clearfix"></div>
Откройте файл shopping_cart.php, найдите:
<?php
if ($messageStack->size('product_action') > 0) {
echo $messageStack->output('product_action');
}
?>
и замените на:
<?php /* // start Get 1 Free
if ($messageStack->size('product_action') > 0) {
echo $messageStack->output('product_action');
} // end Get 1 Free */
?>
далее найдите:
$products_name .= '<br>' . tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'style="width: 45px;"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']) . ' ' . tep_draw_button(NULL, 'glyphicon glyphicon-refresh', NULL, NULL, NULL, 'btn-info btn-xs') . ' ' . tep_draw_button(NULL, 'glyphicon glyphicon-remove', tep_href_link(FILENAME_SHOPPING_CART, 'products_id=' . $products[$i]['id'] . '&action=remove_product'), NULL, NULL, 'btn-danger btn-xs');
и замените на:
// start Get 1 Free
$products_name .= '<br>' . tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'style="width: 45px;"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']) . tep_draw_hidden_field('free[]', $products[$i]['free']) . ' ' . tep_draw_button(NULL, 'glyphicon glyphicon-refresh', NULL, NULL, NULL, 'btn-info btn-xs') . ' ' . tep_draw_button(NULL, 'glyphicon glyphicon-remove', tep_href_link(FILENAME_SHOPPING_CART, 'products_id=' . $products[$i]['id'] . '&action=remove_product'), NULL, NULL, 'btn-danger btn-xs');
// end Get 1 Free
Откройте файл includes/application_top.php, найдите:
} else {
$attributes = ($HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i]]) ? $HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i]] : '';
$cart->add_cart($HTTP_POST_VARS['products_id'][$i], $HTTP_POST_VARS['cart_quantity'][$i], $attributes, false);
}
и замените на:
// Start get 1 free
$isFree = $HTTP_POST_VARS['free'][$i];
if ($isFree != 1) {
$cart->add_cart($HTTP_POST_VARS['products_id'][$i], $HTTP_POST_VARS['cart_quantity'][$i], $attributes, false);
}
// End get 1 free
Откройте файл includes/database_tables.php, найдите:
define('TABLE_CUSTOMERS_INFO', 'customers_info');
и после добавьте:
// Get 1 Free
define('TABLE_GET_1_FREE', 'get_1_free');
Откройте файл includes/classes/shopping_cart.php, найдите:
function count_contents() { // get total number of items in cart
$total_items = 0;
if (is_array($this->contents)) {
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
$total_items += $this->get_quantity($products_id);
и после добавьте:
// start Get 1 free
// If this product qualifies for free product(s) add in the number of free products
if (is_array ($free_product = $this->get1free ($products_id))) {
$total_items += $free_product['quantity'];
}
// end Get 1 free
далее найдите:
function remove($products_id) {
global $customer_id;
unset($this->contents[$products_id]);
// remove from database
if (tep_session_is_registered('customer_id')) {
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
}
и после добавьте:
// start Get 1 Free
// If this product qualifies for free product(s) remove the free products
if (is_array ($free_product = $this->get1free ($products_id))) {
$pid = (int)$free_product['id'];
print '<br>Found Product: ' . $pid;
unset($this->contents[$pid]);
// remove from database
if (tep_session_is_registered('customer_id')) {
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($pid) . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($pid) . "'");
}
}
// end Get 1 Free
далее найдите:
$this->total += tep_add_tax($products_price, $products_tax) * $qty;
$this->weight += ($qty * $products_weight);
и после добавьте:
// start Get 1 Free
// If this product qualifies for free product(s) add in the total weight of free products
if (is_array ($free_product = $this->get1free ($products_id))) {
$this->weight += $free_product['quantity'] * $free_product['weight'];
}
// end Get 1 Free
далее найдите:
$products_array [] = array('id' => $products_id,
'name' => $products['products_name'],
'model' => $products['products_model'],
'image' => $products['products_image'],
'price' => $products_price,
'quantity' => $this->contents[$products_id]['qty'],
'weight' => $products['products_weight'],
'final_price' => ($products_price + $this->attributes_price($products_id)),
'tax_class_id' => $products['products_tax_class_id'],
'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
и после добавьте:
// start Get 1 free
if (is_array ($free_product = $this->get1free ($products_id))) {
// Add the free product to the shopping cart (Customer cannot alter this)
$products_array [] = array('id' => $free_product['id'],
'name' => $free_product['name'],
'model' => $free_product['model'],
'image' => $free_product['image'],
'price' => 0,
'quantity' => $free_product['quantity'],
'weight' => $free_product['weight'],
'final_price' => 0,
'tax_class_id' => $products['products_tax_class_id'],
'attributes' => '',
'free' => 1
);
} //if (is_array
// end Get 1 free
далее найдите:
function unserialize($broken) {
for(reset($broken);$kv=each($broken);) {
$key=$kv['key'];
if (gettype($this->$key)!="user function")
$this->$key=$kv['value'];
}
}
и после добавьте:
// start Get 1 Free
function get1free ($products_id) {
global $languages_id;
$get_1_free_query = tep_db_query("select products_free_id,
products_free_quantity,
products_qualify_quantity,
products_multiple,
get_1_free_expires_date
from " . TABLE_GET_1_FREE . "
where products_id = '" . (int)$products_id . "'
and status = '1'"
);
if (tep_db_num_rows($get_1_free_query) > 0) {
$get_1_free = tep_db_fetch_array($get_1_free_query);
//Check that the offer has not expired
//MNK bugfix 13.08.2007
if (($get_1_free['get_1_free_expires_date'] <= date('Y-m-d H:i:s')) && ($get_1_free['get_1_free_expires_date'] != '0000-00-00 00:00:00')) {
//offer has expired, so update the database and return false
tep_db_query("update " . TABLE_GET_1_FREE . "
set status = '0',
date_status_change = now()
where products_id = '" . (int)$products_id . "'"
);
return false;
} else {
// Offer is valid, so check if the quantity qualifies
$products_quantity = $this->contents[$products_id]['qty'];
if ($products_quantity >= $get_1_free['products_qualify_quantity']) {
// Qualifies, so get the quantity of free products
$free_quantity = 1;
if ($get_1_free['products_multiple'] > 1) {
// BUG FIX from post number 167
// $free_quantity = floor ($products_quantity / $get_1_free['products_qualify_quantity']);
$free_quantity = floor ($products_quantity / $get_1_free['products_qualify_quantity']) * $get_1_free['products_free_quantity'];
// EOF BUG FIX from post number 167
if ($free_quantity > $get_1_free['products_multiple']) {
$free_quantity = $get_1_free['products_multiple'];
}
}
// Get the info on the free product
$products_free_query = tep_db_query("select pd.products_name,
p.products_model,
p.products_image,
p.products_weight
from " . TABLE_PRODUCTS . " p,
" . TABLE_PRODUCTS_DESCRIPTION . " pd
where p.products_id = '" . (int)$get_1_free['products_free_id'] . "'
and pd.products_id = p.products_id
and pd.language_id = '" . (int)$languages_id . "'"
);
$products_free = tep_db_fetch_array($products_free_query);
// Return an array of free product values
$output = array ( 'id' => $get_1_free['products_free_id'],
'quantity' => $free_quantity,
'name' => $products_free['products_name'],
'model' => $products_free['products_model'],
'image' => $products_free['products_image'],
'weight' => $products_free['products_weight']
);
return $output;
} //if ($products_quantity
} //else
}//if (tep_db_num_rows
// offer was not valid (disabled or expired)
return false;
}//function
// end Get 1 Free
Откройте файл includes/languages/russian/product_info.php, найдите:
define('TEXT_CLICK_TO_ENLARGE', 'Увеличить');
и после добавьте:
// Get 1 Free
define('TEXT_GET_1_FREE_PROMOTION', '<strong>Специальное ограниченное предложение:</strong> Купите %u %s и получите %u %s бесплатно!');
define('TEXT_OFFER_ENDS', ' - Предложение действует до');
Откройте, если есть, файл includes/languages/english/product_info.php, найдите:
define('TEXT_CLICK_TO_ENLARGE', 'Click to enlarge');
и после добавьте:
// Get 1 Free
define('TEXT_GET_1_FREE_PROMOTION', '<strong>Special Limited Offer:</strong> Buy %u %s and get %u %s free!');
define('TEXT_OFFER_ENDS', ' - Limited time offer ends');
На этом инсталляция окончена.