<?php
/**
 * Page Template
 *
 * Loaded automatically by index.php?main_page=shopping_cart.<br />
 * Displays shopping-cart contents
 *
 * @package templateSystem
 * @copyright Copyright 2003-2010 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_shopping_cart_default.php 15881 2010-04-11 16:32:39Z wilt $
 */
?>
<div class="centerColumn" id="shoppingCartDefault">
<?php if ($flagHasCartContents) { ?>

<div id="cartInstructionsDisplay" class="content"><?php echo TEXT_INFORMATION; ?></div>
<?php if ($_SESSION['cart']->count_contents() > 0) { ?>
<div class="cart-info clearfix">
  <?php if (!empty($totalsDisplay)) { ?>
    <div class="cartTotalsDisplay important pull-left"><?php echo $totalsDisplay; ?></div>
  <?php } ?>
  <div class="pull-right"><a href="<?php echo zen_href_link(FILENAME_INFO_SHOPPING_CART); ?>" data-featherlight="ajax" class="button button-inverse"><?php echo TEXT_HELP; ?></a></div>
</div>
<br class="clearBoth">
<?php } ?>

<?php if ($messageStack->size('shopping_cart') > 0) echo $messageStack->output('shopping_cart'); ?>

<?php echo zen_draw_form('cart_quantity', zen_href_link(FILENAME_SHOPPING_CART, 'action=update_product', $request_type)); ?>

<?php if ($flagAnyOutOfStock) { ?>
  <?php if (STOCK_ALLOW_CHECKOUT == 'true') {  ?>
    <div class="messageStack messageStackError"><?php echo OUT_OF_STOCK_CAN_CHECKOUT; ?></div>
  <?php } else { ?>
    <div class="messageStack messageStackError"><?php echo OUT_OF_STOCK_CANT_CHECKOUT; ?></div>
  <?php } //endif STOCK_ALLOW_CHECKOUT ?>
<?php } //endif flagAnyOutOfStock ?>

<table  border="0" width="100%" cellspacing="0" cellpadding="0" id="cartContentsDisplay">
  <tr class="tableHeading">
    <th scope="col" id="scProductsHeading"><?php echo TABLE_HEADING_PRODUCTS; ?></th>
    <th scope="col" id="scUnitHeading" class="hidden-sm hidden-xs"><?php echo TABLE_HEADING_PRICE; ?></th>
    <th scope="col" id="scQuantityHeading"><?php echo TABLE_HEADING_QUANTITY; ?></th>
    <th scope="col" id="scTotalHeading"><?php echo TABLE_HEADING_TOTAL; ?></th>
    <th scope="col" id="scRemoveHeading">&nbsp;</th>
  </tr>
  <!-- Loop through all products /-->
<?php foreach ($productArray as $product) { ?>
  <tr class="<?php echo $product['rowClass']; ?>">
    <td class="cartProductDisplay">
      <div class="products-link hidden-sm hidden-xs"><a href="<?php echo $product['linkProductsName']; ?>"><?php echo $product['productsImage']; ?></a></div>
      <div class="products-detail">
        <span class="products-name"><a href="<?php echo $product['linkProductsName']; ?>"><?php echo $product['productsName'] . '<span class="text-danger"><strong>' . $product['flagStockCheck'] . '</strong></span>'; ?></a></span>
        <?php
          echo $product['attributeHiddenField'];
          echo zen_draw_hidden_field('products_id[]', $product['id']);
          if (isset($product['attributes']) && is_array($product['attributes'])) {
          echo '<div class="cartAttribsList">';
          echo '<ul>';
            reset($product['attributes']);
            foreach ($product['attributes'] as $option => $value) {
        ?>
          <li data-toggle="genesis-tooltip" data-title="<?php echo $value['products_options_name']; ?>"><?php echo nl2br($value['products_options_values_name']); ?></li>
        <?php
            }
          echo '</ul>';
          echo '</div>';
          }
        ?>
      </div>
    </td>
    <td class="cartUnitDisplay hidden-sm hidden-xs"><?php //echo $product['productsPriceEach']; ?><?php  $product['products_discount_type']; if($product['products_discount_type'] != 0 ){ echo $product['org_price']; } else { echo $product['productsPriceEach'];  }  ?></td>
    <td class="cartQuantity">
      <?php
        if ($product['flagShowFixedQuantity']) {
          echo $product['showFixedQuantityAmount'] . '<p class="text-danger"><strong>' . $product['flagStockCheck'] . '</strong></p><p>' . $product['showMinUnits'] . '</p>';
        } else {
          echo '<div class="cart-qty"><input class="cart-qty-input" name="cart_quantity[]" value="' . $_SESSION['cart']->get_quantity($product['id']) . '" maxlength="6" size="4" type="text"><div class="cart-qty-control hidden-sm hidden-xs"><a href="#" class="qty-control cart-qty-inc"><i class="fa fa-angle-up"></i></a><a href="#" class="qty-control cart-qty-dec"><i class="fa fa-angle-down"></i></a></div></div></p>';
        }
      ?>
    </td>
    <td class="cartTotalDisplay"><?php echo $product['productsPrice']; ?></td>
    <td class="cartRemoveItemDisplay">
      <?php if ($product['buttonDelete']) { ?>
        <a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, 'action=remove_product&product_id=' . $product['id']); ?>" data-toggle="genesis-tooltip" title="<?php echo ICON_TRASH_ALT; ?>">&times;</a>
      <?php } ?>
    </td>
  </tr>
<?php } // end foreach ($productArray as $product) ?>
  

<?php 
 require_once(DIR_WS_CLASSES . 'order.php');
 $order = new order();
//  print"<pre>";
//  print_r($order); 

 include_once(DIR_WS_MODULES . $template_dir . '/inc_gp.php'); // Group Discount
 include_once(DIR_WS_MODULES . $template_dir . '/inc_bt.php'); // Better Together
 include_once(DIR_WS_MODULES . $template_dir . '/inc_qd.php'); // Quantity Discount
 include_once(DIR_WS_MODULES . $template_dir . '/inc_td.php'); // Table Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_md.php'); // Manufacturer Discount
 include_once(DIR_WS_MODULES . $template_dir . '/inc_cd.php'); // Combination Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_bs.php'); // Big Spender Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_bo.php'); // BOGO Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_bc.php'); // Big Chooser Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_fgc.php'); // Free Gift Chooser Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_fgs.php'); // Free Gift Spender Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_cased.php'); // Case Discounts
 include_once(DIR_WS_MODULES . $template_dir . '/inc_fd.php'); // Frequency Discount
?>

<?php 

// $newsub = $order->info['subtotal'];
// UK VAT use this instead 
 //$newsub = $_SESSION['cart']->show_total();
	$newsub = $cartShowTotalWithDIsc;
  	$shownewsub = 0; 
if (isset($gp['total']) && $gp['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $gp['total']; 
}
if (isset($bt['total']) && $bt['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $bt['total']; 
}
if (isset($qd['total']) && $qd['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $qd['total']; 
}
if (isset($td['total']) && $td['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $td['total']; 
}
if (isset($md['total']) && $md['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $md['total']; 
}
if (isset($cd['total']) && $cd['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $cd['total']; 
}
if (isset($bc['total']) && $bc['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $bc['total']; 
}
if (isset($bs['total']) && $bs['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $bs['total']; 
}
if (isset($bo['total']) && $bo['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $bo['total']; 
}
if (isset($fgc['total']) && $fgc['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $fgc['total']; 
}
if (isset($fgs['total']) && $fgs['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $fgs['total']; 
}
if (isset($cased['total']) && $cased['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $cased['total']; 
}
if (isset($fd['total']) && $fd['total'] > 0) {
   $shownewsub = 1; 
   $newsub -= $fd['total']; 
}
if ($shownewsub) { 
	
// 		echo '<div id="cartSubTotal">';
// 		echo SUB_TITLE_SUB_TOTAL . ": "; 
// 		echo $currencies->format($cartShowTotalWithDIsc, true, $order->info['currency'], $order->info['currency_value']);
// 		echo '</div>';
// 		echo '<div id="cartNewSubTotal">';
// 		echo SUBTOTAL_POSTDISCOUNT . ": "; 
// 		echo $currencies->format($newsub, true, $order->info['currency'], $order->info['currency_value']);
// 		echo '</div>';
		echo '<tr class="tableFooter">
    <td></td>
    <td></td>
    <td class="cartSubTotalText important">'; echo SUB_TITLE_SUB_TOTAL; echo '</td>
    <td class="cartSubTotal important">';echo $currencies->format($cartShowTotalWithDIsc, true, $order->info['currency'], $order->info['currency_value']); echo '</td>
    <td></td>
  </tr>
  <tr class="tableFooter">
    <td></td>
    <td></td>
    <td class="cartSubTotalText important">'; echo SUBTOTAL_POSTDISCOUNT; echo '</td>
    <td class="cartSubTotal important">';echo $currencies->format($newsub, true, $order->info['currency'], $order->info['currency_value']); echo '</td>
    <td></td>
  </tr>
</table>';
  
} else { ?> <?php
	echo '<tr class="tableFooter">
    <td></td>
    <td></td>
    <td class="cartSubTotalText important">'; echo SUB_TITLE_SUB_TOTAL; echo '</td>
    <td class="cartSubTotal important">';echo $cartShowTotal; echo '</td>
    <td></td>
  </tr>
</table>';
}
?>







<!--bof shopping cart buttons-->
<div class="cart-buttons">
  <?php if (SHOW_SHIPPING_ESTIMATOR_BUTTON == '1') { ?>
  <div class="ship-estimator-button pull-left">
    <a href="<?php echo zen_href_link(FILENAME_POPUP_SHIPPING_ESTIMATOR); ?>" data-featherlight="iframe" class="button button-inverse">
      <?php echo BUTTON_SHIPPING_ESTIMATOR_ALT; ?>
    </a>
  </div>
  <?php } ?>
  <?php if (SHOW_SHOPPING_CART_UPDATE == 2 or SHOW_SHOPPING_CART_UPDATE == 3) { ?>
  <div class="pull-left cart-update" data-toggle="pt-tooltip" data-title="<?php echo ICON_UPDATE_ALT; ?>"><button type="submit" class="button button-inverse"><?php echo TEXT_CART_UPDATE; ?></button></div>
  <?php } ?>

  <?php  if (defined('MODULE_PAYMENT_PAYPALWPP_STATUS') && MODULE_PAYMENT_PAYPALWPP_STATUS == 'True') { ?>
  <div class="paypal-button pull-right">
    <?php include(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/tpl_ec_button.php'); ?>
  </div>
  <?php } ?>
  <div class="pull-right"><?php echo '<a href="' . zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '" class="button">' . BUTTON_CHECKOUT_ALT . '</a>'; ?></div>

</div>
<div class="clearfix"></div>
<!--eof shopping cart buttons-->
</form>

<?php
      if (SHOW_SHIPPING_ESTIMATOR_BUTTON == '2') {
/**
 * load the shipping estimator code if needed
 */
?>
      <?php require(DIR_WS_MODULES . zen_get_module_directory('shipping_estimator.php')); ?>

<?php
      }
?>
<?php
  } else {
?>

<h2 id="cartEmptyText" class="important"><?php echo TEXT_CART_EMPTY; ?></h3><br>

<?php
$show_display_shopping_cart_empty = $db->Execute(SQL_SHOW_SHOPPING_CART_EMPTY);

while (!$show_display_shopping_cart_empty->EOF) {
?>

<?php
  if ($show_display_shopping_cart_empty->fields['configuration_key'] == 'SHOW_SHOPPING_CART_EMPTY_FEATURED_PRODUCTS') { ?>
<?php
/**
 * display the Featured Products Center Box
 */
?>
<?php require($template->get_template_dir('tpl_modules_featured_products.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_featured_products.php'); ?>
<?php } ?>

<?php
  if ($show_display_shopping_cart_empty->fields['configuration_key'] == 'SHOW_SHOPPING_CART_EMPTY_SPECIALS_PRODUCTS') { ?>
<?php
/**
 * display the Special Products Center Box
 */
?>
<?php require($template->get_template_dir('tpl_modules_specials_default.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_specials_default.php'); ?>
<?php } ?>

<?php
  if ($show_display_shopping_cart_empty->fields['configuration_key'] == 'SHOW_SHOPPING_CART_EMPTY_NEW_PRODUCTS') { ?>
<?php
/**
 * display the New Products Center Box
 */
?>
<?php require($template->get_template_dir('tpl_modules_whats_new.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_whats_new.php'); ?>
<?php } ?>

<?php
  if ($show_display_shopping_cart_empty->fields['configuration_key'] == 'SHOW_SHOPPING_CART_EMPTY_UPCOMING') {
    include(DIR_WS_MODULES . zen_get_module_directory(FILENAME_UPCOMING_PRODUCTS));
  }
?>
<?php
  $show_display_shopping_cart_empty->MoveNext();
} // !EOF
?>
<?php
  }
?>
</div>
