public function process($values = null) { //It seems that the parameter $values is not used at all //I gave it a default value of null. //Anas, 29, October, 2008 $order = new CartOrder(); $customer = $_SESSION['authenticated_user']; $billing_adr = $_SESSION['cart_checkout']['address']['billing_address']; $shipping_adr = $_SESSION['cart_checkout']['address']['shipping_address']; $payment = $_SESSION['cart_checkout']['payment']; $shipping = $_SESSION['cart_checkout']['shipping']; $order->setCustomer($customer->getId()); $order->setCustomerName($customer->getName()); $order->setCustomerAddress($billing_adr->getId()); $order->setCustomerTelephone($customer->getPhone()); $order->setCustomerEmail($customer->getEmail()); $order->setBillingName($customer->getName()); $order->setBillingAddress($billing_adr->getId()); $order->setDeliveryName($customer->getName()); $order->setDeliveryAddress($shipping_adr->getId()); $order->setPaymentMethod($payment->getName()); $order->setPaymentModuleCode($payment->getClass()); $order->setShippingMethod($shipping->getName()); $order->setShippingModuleCode($shipping->getClass()); $order->setShippingCost($shipping->getCost()); $order->setCurrency('CAD'); $order->setCurrencyValue('1.000000'); $order->setDeliveryDirections($_SESSION['cart_checkout']['delivery_direction']); $cartitems = CartBasket::getUserCartBaskets($_SESSION['authenticated_user']->getId()); $subtotal = 0; $tax = 0; foreach ($cartitems as $item) { $subtotal += $item->getPrice() * $item->getQuantity(); $taxclass = $item->getProduct()->getTaxClass(); $taxrate = CartTaxRate::getTaxRate($taxclass, $shipping_adr)->getRate(); $tax += $taxrate / 100 * ($item->getPrice() * $item->getQuantity()); } $order->setSubTotal($subtotal); $order->setTax($tax); $order->setTotal($subtotal + $tax + $shipping->getCost()); $order->setStatus(1); $order->setIp_address($_SERVER['REMOTE_ADDR']); $order->setDate_purchased(date('Y-m-d H:i:s')); $order->setPaypal_ipn_id(@$_REQUEST["txn_id"]); $order->save(); foreach ($cartitems as $item) { $product = new CartOrderProduct(); $product->setOrderId($order->getId()); $product->setProduct($item->getProduct()->getId()); $product->setModel($item->getProduct()->getModel()); $product->setName($item->getProduct()->getName()); $product->setPrice($item->getPrice()); $product->setFinalPrice($item->getQuantity() * $item->getPrice()); $product->setQuantity($item->getQuantity()); $taxclass = $item->getProduct()->getTaxClass(); $taxrate = CartTaxRate::getTaxRate($taxclass, $billing_adr)->getRate(); $product->setTax($taxrate); $product->save(); if ($item->getProduct()->getAttId()) { $product_atts = CartBasketAttribute::getCartBasketProductAttributes($item->getProduct()->getId() . ':' . $item->getProduct()->getAttId()); foreach ($product_atts as $product_att) { $att = new CartOrderProductAttribute(); $att->setOrderid($order->getId()); $att->setProductid($product->getId()); $option = new CartProductOption($product_att['products_options_id']); // works $att->setProducts_options($option->getName()); // works $option_value = new CartProductOptionValue($product_att['products_options_value_id']); $att->setProducts_options_values($option_value->getName()); $sql = 'select * from cart_products_attributes where options_id=' . $product_att['products_options_id'] . ' and '; $sql .= 'options_values_id=' . $product_att['products_options_value_id'] . ' and '; $sql .= 'products_id=' . $item->getProduct()->getId(); $r = Database::singleton()->query_fetch($sql); $att->setOptions_values_price($r['options_values_price']); $att->save(); } } } $_SESSION['cart_checkout']['order'] = $order; }
private function setUpCartDetail1() { if (isset($_SESSION['authenticated_user'])) { $cartitems = CartBasket::getUserCartBaskets($_SESSION['authenticated_user']->getId()); } else { $cartitems = CartBasket::getUserCartBaskets(); } if (isset($_SESSION['cart_checkout']['address']['shipping_address'])) { $tax = 0.0; $totalAmount = 0.0; foreach ($cartitems as $item) { $rate = CartTaxRate::getTaxRate($item->getProduct()->getTaxClass(), $_SESSION['cart_checkout']['address']['shipping_address'])->getRate(); $tax += $rate / 100 * ($item->getPrice() * $item->getQuantity()); $totalAmount += $item->getPrice() * $item->getQuantity(); } $totalAmount += $tax; $this->smarty->assign('tax', $tax); } $shipping = @$_SESSION['cart_checkout']['shipping']; if ($shipping) { $totalAmount += $shipping->getCost(); } $this->smarty->assign('shipping', $shipping); $this->smarty->assign('cart', $cartitems); //$this->smarty->assign('totalAmount', $totalAmount); }