Skip to content

Commit

Permalink
cart actions and rewrite changes
Browse files Browse the repository at this point in the history
  • Loading branch information
osc2nuke committed May 2, 2015
1 parent af842bc commit 0c287c4
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 136 deletions.
94 changes: 9 additions & 85 deletions includes/application_top.php
Expand Up @@ -316,96 +316,19 @@
$messageStack = new messageStack;

// Shopping cart actions
if (isset($_GET['action'])) {
if ( isset($_GET['action']) && !empty($_GET['action']) ) {
// redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled
if ($session_started == false) {
tep_redirect(tep_href_link(FILENAME_COOKIE_USAGE));
}

if (DISPLAY_CART == 'true') {
$goto = FILENAME_SHOPPING_CART;
$parameters = array('action', 'cPath', 'products_id', 'pid');
} else {
$goto = $PHP_SELF;
if ($_GET['action'] == 'buy_now') {
$parameters = array('action', 'pid', 'products_id');
} else {
$parameters = array('action', 'pid');
}
}
include(DIR_WS_CLASSES . 'actions.php');

osC_Actions::parse($_GET['action']);

/*
switch ($_GET['action']) {
// customer wants to update the product quantity in their shopping cart
case 'update_product' :

if ( isset($_POST['products']) && is_array($_POST['products']) && !empty($_POST['products']) ) {
foreach ( $_POST['products'] as $item_id => $quantity ) {
if ( !is_numeric($item_id) || !is_numeric($quantity) ) {
return false;
}
$cart->update($item_id, $quantity);
}
}
tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
break;

// customer adds a product from the products page
case 'add_product' :
if (isset($_POST['products_id']) && is_numeric($_POST['products_id'])) {

$osC_Product = new osC_Product($_POST['products_id']);

if ( $osC_Product->hasVariants() ) {
if ( isset($_POST['variants']) && is_array($_POST['variants']) && !empty($_POST['variants']) ) {
if ( $osC_Product->variantExists($_POST['variants']) ) {
$cart->add_cart($osC_Product->getProductVariantID($_POST['variants']));

} else {
tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $_GET['products_id']));

return false;
}

} else {
tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $_GET['products_id']));

return false;
}
} else {
$cart->add_cart($osC_Product->getID());
}
}
$messageStack->add_session('product_action', sprintf(PRODUCT_ADDED, tep_get_products_name((int)$_POST['products_id'])), 'success');
tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
break;


// customer removes a product from their shopping cart
case 'remove_product' : if (isset($_GET['item_id'])) {
$cart->remove($_GET['item_id']);
//$messageStack->add_session('product_action', sprintf(PRODUCT_REMOVED, tep_get_products_name($_GET['products_id'])), 'warning');
}
tep_redirect(tep_href_link($goto, null));
break;
// performed by the 'buy now' button in product listings and review page
case 'buy_now' :
if (isset($_GET['products_id']) && is_numeric($_GET['products_id'])) {

$osC_Product = new osC_Product($_GET['products_id']);

if ( $osC_Product->hasVariants() ) {

tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $_GET['products_id']));

return false;

} else {
$cart->add_cart($osC_Product->getID());
$messageStack->add_session('product_action', sprintf(PRODUCT_ADDED, tep_get_products_name((int)$_GET['products_id'])), 'success');
}
}
tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
break;
case 'notify' : if (tep_session_is_registered('customer_id')) {
if (isset($_GET['products_id'])) {
$notify = $_GET['products_id'];
Expand Down Expand Up @@ -453,9 +376,10 @@
}
tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
break;
}
}
*/
}

// include the who's online functions
require(DIR_WS_FUNCTIONS . 'whos_online.php');
tep_update_whos_online();
Expand Down
38 changes: 38 additions & 0 deletions includes/classes/actions.php
@@ -0,0 +1,38 @@
<?php
/*
$Id: $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2007 osCommerce
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License v2 (1991)
as published by the Free Software Foundation.
*/

/**
* The osC_Actions class loads action modules to execute specific tasks
*/

class osC_Actions {

/**
* Loads the action module to execute
*
* @param string $module The name of the module to execute
* @access public
*/

public static function parse($module) {
$module = basename($module);

if ( !empty($module) && file_exists('includes/modules/actions/' . $module . '.php') ) {
include('includes/modules/actions/' . $module . '.php');

call_user_func(array('osC_Actions_' . $module, 'execute'));
}
}
}
?>
71 changes: 71 additions & 0 deletions includes/modules/actions/cart_add.php
@@ -0,0 +1,71 @@
<?php
/*
$Id: $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2007 osCommerce
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License v2 (1991)
as published by the Free Software Foundation.
*/

class osC_Actions_cart_add {
function execute() {
global $PHP_SELF, $cPath, $messageStack, $osC_Session, $cart, $osC_Product;

if ( !isset($osC_Product) ) {
$id = false;

foreach ( $_GET as $key => $value ) {
//if ( (is_numeric($key) || preg_match('/^[a-zA-Z0-9 -_]*$/', $key)) && ($key != $osC_Session->getName()) ) {
if ( (is_numeric($key) || preg_match('/^[a-zA-Z0-9 -_]*$/', $key)) ) {
$id = $key;
}

break;
}

if ( ($id !== false) && osC_Product::checkEntry($id) ) {
$osC_Product = new osC_Product($id);
}
}

if ( isset($osC_Product) ) {
if ( $osC_Product->hasVariants() ) {
if ( isset($_POST['variants']) && is_array($_POST['variants']) && !empty($_POST['variants']) ) {
if ( $osC_Product->variantExists($_POST['variants']) ) {
$cart->add_cart($osC_Product->getProductVariantID($_POST['variants']));
} else {
tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, $osC_Product->getKeyword()));

return false;
}
} else {
tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, $osC_Product->getKeyword()));

return false;
}
} else {
$cart->add_cart($osC_Product->getID());
}
}
$messageStack->add_session('product_action', sprintf(PRODUCT_ADDED, $osC_Product->getTitle()), 'success');

if (DISPLAY_CART == 'true') {
$goto = FILENAME_SHOPPING_CART;
tep_redirect(tep_href_link($goto, null));
} else {
$goto = $PHP_SELF;
if(isset($_GET['cPath'])){
tep_redirect(tep_href_link($goto.'?cPath='.$_GET['cPath'], null));
}else{
tep_redirect(tep_href_link($goto, $osC_Product->getKeyword()));
}
}

}
}
?>
38 changes: 38 additions & 0 deletions includes/modules/actions/cart_remove.php
@@ -0,0 +1,38 @@
<?php
/*
$Id: $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2007 osCommerce
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License v2 (1991)
as published by the Free Software Foundation.
*/

class osC_Actions_cart_remove {
function execute() {
global $PHP_SELF, $messageStack, $cart;



if ( is_numeric($_GET['item']) ) {
$messageStack->add_session('product_action', sprintf(PRODUCT_REMOVED, $cart->contents[$_GET['item']]['name']), 'warning');
$cart->remove($_GET['item']);
}

if (DISPLAY_CART == 'true') {
$goto = FILENAME_SHOPPING_CART;
$parameters = array('action', 'cPath', 'products_id', 'pid');
} else {
$goto = $PHP_SELF;
$parameters = array('action', 'pid');

}

tep_redirect(tep_href_link($goto, null));
}
}
?>
41 changes: 41 additions & 0 deletions includes/modules/actions/cart_update.php
@@ -0,0 +1,41 @@
<?php
/*
$Id: $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2015 osCommerce
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License v2 (1991)
as published by the Free Software Foundation.
*/

class osC_Actions_cart_update {
function execute() {
global $PHP_SELF, $cart;

if ( isset($_POST['products']) && is_array($_POST['products']) && !empty($_POST['products']) ) {
foreach ( $_POST['products'] as $item_id => $quantity ) {
if ( !is_numeric($item_id) || !is_numeric($quantity) ) {
return false;
}

$cart->update($item_id, $quantity);

}
}

if (DISPLAY_CART == 'true') {
$goto = FILENAME_SHOPPING_CART;
$parameters = array('action', 'cPath', 'products_id', 'pid');
} else {
$goto = $PHP_SELF;
$parameters = array('action', 'pid');

}
tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
}
}
?>
32 changes: 17 additions & 15 deletions includes/modules/product_listing.php
Expand Up @@ -9,7 +9,7 @@
Released under the GNU General Public License
*/

$listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id');

// create column list
Expand Down Expand Up @@ -146,18 +146,22 @@

$prod_list_contents .= '<div class="item list-group-item col-sm-4">';
$prod_list_contents .= ' <div class="productHolder equal-height">';
if (isset($_GET['manufacturers_id']) && tep_not_null($_GET['manufacturers_id'])) {
$prod_list_contents .= ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $_GET['manufacturers_id'] . '&products_id=' . $osC_Product->getID()) . '">' . tep_image(DIR_WS_IMAGES . $osC_Product->getImage(), $osC_Product->getTitle(), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, NULL, NULL, 'img-responsive thumbnail group list-group-image') . '</a>';
} else {
$prod_list_contents .= ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($sort ? 'sort=' . $sort . '&' : '') . ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $osC_Product->getID()) . '">' . tep_image(DIR_WS_IMAGES . $osC_Product->getImage(), $osC_Product->getTitle(), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, NULL, NULL, 'img-responsive thumbnail group list-group-image') . '</a>';

if (isset($_GET['manufacturers']) && tep_not_null($_GET['manufacturers'])) {
$prod_list_contents .= ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, $osC_Product->getKeyword() .'&manufacturers_id=' . $_GET['manufacturers']) . '">' . tep_image(DIR_WS_IMAGES . $osC_Product->getImage(), $osC_Product->getTitle(), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, NULL, NULL, 'img-responsive thumbnail group list-group-image') . '</a>';
} else {
$prod_list_contents .= ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, $osC_Product->getKeyword() . '&' .($sort ? 'sort=' . $sort . '&' : '') . ($cPath ? 'cPath=' . $cPath . '&' : '')) . '">' . tep_image(DIR_WS_IMAGES . $osC_Product->getImage(), $osC_Product->getTitle(), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, NULL, NULL, 'img-responsive thumbnail group list-group-image') . '</a>';
}

$prod_list_contents .= ' <div class="caption">';
$prod_list_contents .= ' <h2 class="group inner list-group-item-heading">';
if (isset($_GET['manufacturers_id']) && tep_not_null($_GET['manufacturers_id'])) {
$prod_list_contents .= ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $_GET['manufacturers_id'] . '&products_id=' . $osC_Product->getID()) . '">' . $osC_Product->getTitle() . '</a>';
} else {
$prod_list_contents .= ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $osC_Product->getID()) . '">' . $osC_Product->getTitle() . '</a>';

if (isset($_GET['manufacturers']) && tep_not_null($_GET['manufacturers'])) {
$prod_list_contents .= ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, $osC_Product->getKeyword() .'&manufacturers_id=' . $_GET['manufacturers'] ) . '">' . $osC_Product->getTitle() . '</a>';
} else {
$prod_list_contents .= tep_link_object(tep_href_link(FILENAME_PRODUCT_INFO, $osC_Product->getKeyword() . ($cPath ? '&cPath=' . $cPath : '')), $osC_Product->getTitle()) . '&nbsp;';
}

$prod_list_contents .= ' </h2>';

$prod_list_contents .= ' <p class="group inner list-group-item-text">' . strip_tags($osC_Product->getDescription(), '<br>') . '&hellip;</p><div class="clearfix"></div>';
Expand All @@ -180,12 +184,10 @@
}

$prod_list_contents .= ' <div class="row">';
//if (tep_not_null($listing['specials_new_products_price'])) {
// $prod_list_contents .= ' <div class="col-xs-6"><div class="btn-group" role="group"><button type="button" class="btn btn-default"><del>' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</del></span>&nbsp;&nbsp;<span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</button></div></div>';
// } else {
$prod_list_contents .= ' <div class="col-xs-6"><div class="btn-group" role="group"><button type="button" class="btn btn-default">' . $osC_Product->getPriceFormated(true) . '</button></div></div>';
//}
$prod_list_contents .= ' <div class="col-xs-6 text-right">' . tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action', 'sort', 'cPath')) . 'action=buy_now&products_id=' . $osC_Product->getID()), NULL, NULL, 'btn-success btn-sm') . '</div>';

$prod_list_contents .= ' <div class="col-xs-6"><div class="btn-group" role="group"><button type="button" class="btn btn-default">' . $osC_Product->getPriceFormated(true) . '</button></div></div>';
$prod_list_contents .= ' <div class="col-xs-6 text-right">' . tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'cart', tep_href_link(basename($PHP_SELF), $osC_Product->getKeyword() . '&' . tep_get_all_get_params(array('action')) . 'action=buy_now'), NULL, NULL, 'btn-success btn-sm') . '</div>';

$prod_list_contents .= ' </div>';

$prod_list_contents .= ' </div>';
Expand Down

0 comments on commit 0c287c4

Please sign in to comment.