<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 
/**
* @version $Id: ro_basket.php,v 1.11 2005/01/27 19:34:03 soeren_nb Exp $
* @package mambo-phpShop
* @subpackage HTML
* Contains code from PHPShop(tm):
* 	@copyright (C) 2000 - 2004 Edikon Corporation (www.edikon.com)
*	Community: www.phpshop.org, forums.phpshop.org
* Conversion to Mambo and the rest:
* 	@copyright (C) 2004-2005 Soeren Eberhardt
*
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* mambo-phpShop is Free Software.
* mambo-phpShop comes with absolute no warranty.
*
* www.mambo-phpshop.net
* This is the read-only version of the shopping basket
**/
mm_showMyFileName( __FILE__ );

require_once(CLASSPATH."ps_product.php");
$ps_product = new ps_product;
require_once(CLASSPATH."ps_product_category.php");
$ps_product_category = new ps_product_category;
require_once(CLASSPATH."ps_shipping_method.php");
require_once( CLASSPATH. 'ps_checkout.php');
$ps_checkout = new ps_checkout;
  
if ($cart["idx"] == 0) {
 echo $empty_cart;
 $checkout = False;
}
else {    
 $checkout = True;
?>
<table width="100%" cellspacing="0" cellpadding="4" border="0">
    <tr align="left" class="sectiontableheader">
    <th><?php 
          echo $PHPSHOP_LANG->_PHPSHOP_CART_NAME;
         ?></th>
    <th><?php 
          echo $PHPSHOP_LANG->_PHPSHOP_CART_SKU;
         ?></th>
    <th><?php 
          echo $PHPSHOP_LANG->_PHPSHOP_CART_PRICE;
         ?></th>
    <th><?php 
          echo $PHPSHOP_LANG->_PHPSHOP_CART_QUANTITY;
         ?></th>
    <th><?php 
          echo $PHPSHOP_LANG->_PHPSHOP_CART_SUBTOTAL;
         ?></th>
    </tr>
    <?php
      $total = 0;
      $vars["zone_qty"] = 0;
      $weight_total = 0;
      $order_shipping = 0;
      for ($i=0;$i<$cart["idx"];$i++) {
        // Added for the zone shipping module
        $vars["zone_qty"] += $cart[$i]["quantity"];
    
        if ($i % 2) $row_color = SEARCH_COLOR_2;
           else $row_color = SEARCH_COLOR_1;
    ?>
    <tr valign="top" bgcolor="<?php echo $row_color ?>">
    <input type="hidden" name="option" value="com_phpshop" />
    <input type="hidden" name="ship_to_info_id" value="<?php echo $ship_to_info_id ?>" />
    
    <td><?php
          // Get product parent id if exists
          $product_parent_id=$ps_product->get_field($cart[$i]["product_id"],"product_parent_id");
          // Get flypage for this product
          $flypage = $ps_product->get_flypage($cart[$i]["product_id"]);
          // Build URL based on whether item or product
          if ($product_parent_id)
             $url = $sess->url(URL . "index.php?page=$flypage&product_id=$product_parent_id");
          else
             $url = $sess->url(URL . "index.php?page=$flypage&product_id=" . $cart[$i]["product_id"]);
          echo "<a href=\"$url\">";
          // Display product name
          echo "<strong>" . $ps_product->get_field($cart[$i]["product_id"], "product_name") . "</strong>";
          echo "</a>";
          // Display advanced attribute values
          echo "<br />".$cart[$i]["description"];
          
          // Display attribute values if this an item
          if ($product_parent_id) {
            $db_detail=$ps_product->attribute_sql($cart[$i]["product_id"],$product_parent_id);
            while ($db_detail->next_record()) {
           echo "<br />" . $db_detail->f("attribute_value"); 
            }
          }
         ?></td>
    <td><?php
          echo $ps_product->get_field($cart[$i]["product_id"], "product_sku");
         ?></td>
    <td><?php
          // $price = $ps_product->get_price($cart[$i]["product_id"]);
          $price = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"],$cart[$i]["description"]);
          printf("%.2f", $price["product_price"]);
         ?></td>
    <td> 
         <?php echo $cart[$i]["quantity"];?> </td>
    <td><?php
          $subtotal = round( $price["product_price"] * $cart[$i]["quantity"], 2);
          $total += $subtotal;
          echo $CURRENCY_DISPLAY->getFullValue($subtotal);
          
         ?></td>
    </tr>
    <?php
        $weight_subtotal = ps_shipping_method::get_weight($cart[$i]["product_id"]) * $cart[$i]['quantity'];
        $weight_total += $weight_subtotal; 
      } // End for loop
    ?>
    <tr class="sectiontableentry1">
        <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_CART_SUBTOTAL ?>:
        </td> 
        <td><?php  echo $CURRENCY_DISPLAY->getFullValue($total); ?>
        </td>
    </tr>
    <?php 
    $payment_discount = $ps_checkout->get_payment_discount($payment_method_id);
    if ( PAYMENT_DISCOUNT_BEFORE == '1') { 
        if( $payment_discount != 0.00 ) {
        $total -= $payment_discount;
                ?>
            <tr class="sectiontableentry2">
                <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_PAYMENT_METHOD_LIST_DISCOUNT ?>:
                </td> 
                <td><?php
                    echo $CURRENCY_DISPLAY->getFullValue($payment_discount);
                ?>
                </td>
            </tr>
            <?php 
        }   
        /* COUPON DISCOUNT */
        if( PSHOP_COUPONS_ENABLE=='1' && @$_SESSION['coupon_redeemed']==true ) {
          $total -= $_SESSION['coupon_discount'];
        ?>
          <tr class="sectiontableentry1">
            <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_COUPON_DISCOUNT ?>:
            </td> 
            <td colspan="3"><?php
              echo "- ".$CURRENCY_DISPLAY->getFullValue( $_SESSION['coupon_discount'] ); ?>
            </td>
          </tr>
        <?php
        }
    }
    /* SHOW TAX */
?>
    <tr class="sectiontableentry1">
        <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_CART_TAX ?>: </td> 
    <td><?php
        if ($weight_total !=0 or TAX_VIRTUAL) {
                $order_taxable = $ps_checkout->calc_order_taxable($vars);
    
                if (PAYMENT_DISCOUNT_BEFORE == '1')
                    $order_taxable -= $payment_discount;	
                if( !empty($_SESSION['coupon_discount']) ) {
                    $order_taxable -= $_SESSION['coupon_discount'];
                }
                $order_tax = $ps_checkout->calc_order_tax($order_taxable, $vars);
        } else {
            $order_tax = 0;
        } 
        $order_tax = round( $order_tax, 2 );
        echo $CURRENCY_DISPLAY->getFullValue($order_tax);
    ?>
    </td>
    </tr>
    <? if ((PSHOP_SHIPPING_MODULE!="no_shipping" || !empty($shipping_rate_id)) 
            && (CHECKOUT_STYLE =='1' || CHECKOUT_STYLE=='3') ) { ?>
    <tr class="sectiontableentry2">
        <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_CART_SHIPPING ?>: </td> 
    <td><?php
        $order_shipping = $ps_checkout->_SHIPPING->get_rate( $vars );
        echo $CURRENCY_DISPLAY->getFullValue($order_shipping);
?>
    </td>
    </tr>
    <?php

    if( PAYMENT_DISCOUNT_BEFORE != '1') {
        if ($payment_discount != 0.00 ) { ?>
            <tr class="sectiontableentry2">
                <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_PAYMENT_METHOD_LIST_DISCOUNT ?>:
                </td> 
                <td><?php
                $total -= $payment_discount;
                if (intval($payment_discount) > 0) {
        
                    echo $CURRENCY_DISPLAY->getFullValue($payment_discount-($payment_discount*2));
                }
                else {
                    echo $CURRENCY_DISPLAY->getFullValue(abs($payment_discount));
                }
                $total -= $payment_discount;
                
          ?>
                </td>
            </tr>
<?php
        }
        /* COUPON DISCOUNT */
        if( PSHOP_COUPONS_ENABLE=='1' && @$_SESSION['coupon_redeemed']==true ) {
          $total -= $_SESSION['coupon_discount'];
        ?>
          <tr class="sectiontableentry1">
            <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_COUPON_DISCOUNT ?>:
            </td> 
            <td colspan="3"><?php
              echo "- ".$CURRENCY_DISPLAY->getFullValue( $_SESSION['coupon_discount'] ); ?>
            </td>
          </tr>
        <?php
        }
  ?> 
    <tr>
        <td colspan="3">&nbsp;</td>
        <td colspan="2"><hr /></td>
    </tr><?php 
    } ?>
        
    <tr>
        <td colspan="4" align="right"><?php echo $PHPSHOP_LANG->_PHPSHOP_CART_TOTAL ?>: </td>
        <td><? 
        if (PAYMENT_DISCOUNT_BEFORE != '1') { 
            echo "<strong>";
        }
        $order_total = $order_tax + $order_shipping + $total;
        
        echo $CURRENCY_DISPLAY->getFullValue($order_total);
                       
        if (PAYMENT_DISCOUNT_BEFORE != '1') { 
            echo "<strong>";
        }
                     ?>
        </td>
    </tr>
    <?php 
  }
    ?>
</table>
<?php
}
?>
