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; }
public function getValues() { $sql = 'select products_options_values_id from cart_products_options_values_to_products_options where products_options_id=' . e($this->getId()); $rs = Database::singleton()->query_fetch_all($sql); $a = array(); foreach ($rs as $r) { $r = new CartProductOptionValue($r['products_options_values_id']); $cur =& $a[]; $cur['id'] = $r->getId(); $cur['value'] = $r->getName(); } return $a; }
/** * Build and return admin interface * * Any module providing an admin interface is required to have this function, which * returns a string containing the (x)html of it's admin interface. * @return string */ public function getAdminInterface() { switch (@$_REQUEST['section']) { case 'attributes': $this->addJS('/modules/Cart/js/optionvalueedit.js'); switch (@$_REQUEST['action']) { case 'values': $option = new CartProductOption($_REQUEST['id']); return json_encode($option->getValues()); die; case 'addedit': $option = new CartProductOption(@$_REQUEST['cartproductoption_id']); $form = $option->getAddEditForm(); if (isset($_REQUEST['delete_value'])) { $v = new CartProductOptionValue(trim($_REQUEST['delete_value'], 'delete_')); $v->delete(); die; } if (isset($_REQUEST['value'])) { foreach (@$_REQUEST['value'] as $key => $value) { $v = new CartProductOptionValue($key); $v->setName($value); $v->save(); } } if (isset($_REQUEST['newvalue'])) { foreach (@$_REQUEST['newvalue'] as $key => $value) { $v = new CartProductOptionValue(); $v->setName($value); $v->setLanguage_id(1); $v->optionid = $option->getId(); $v->save(); } } if (!$form->validate() || !$form->isSubmitted() || !isset($_REQUEST['cartproductoption_submit']) && !isset($_REQUEST['valuesubmit'])) { $this->smarty->assign('form', $form); $this->smarty->assign('option', $option); if ($option->getId()) { $this->smarty->assign('values', $option->getOptionsValues()); } return $this->smarty->fetch('admin/optionsedit.tpl'); } break; case 'delete': $option = new CartProductOption(@$_REQUEST['cartproductoption_id']); $option->delete(); } $options = CartProductOption::getAllCartProductOptions(); $this->smarty->assign('options', $options); return $this->smarty->fetch('admin/options.tpl'); case 'products': require_once 'include/CartProduct.php'; switch (@$_REQUEST['action']) { case 'addedit': if (isset($_REQUEST['delete_att'])) { $a = new CartProductAttribute($_REQUEST['delete_att']); $a->delete(); die; } if (isset($_REQUEST['delete_altimage'])) { $sql = 'delete from cart_products_images where id=' . e($_REQUEST['delete_altimage']); Database::singleton()->query($sql); die; } $this->addJS('/modules/Cart/js/productedit.js'); $product = new CartProduct(@$_REQUEST['cartproduct_products_id']); $form = $product->getAddEditForm(); if (!isset($_REQUEST['cartproduct_submit'])) { return $form->display(); } break; case 'delete': $product = new CartProduct(@$_REQUEST['cartproduct_products_id']); $product->delete(); break; case 'auto': $array = CartProduct::toArray($_REQUEST['value']); $rs = array_slice($array, 1, count($array), true); $str = '<ul>'; foreach ($rs as $key => $r) { $str .= '<li id="' . $key . '">' . $r . '</li>'; } $str .= '</ul>'; return $str; } require_once 'Pager.php'; $pagerOptions = array('mode' => 'Sliding', 'delta' => 5, 'perPage' => 20, 'append' => false, 'path' => '/', 'fileName' => "Cart§ion=products&pageID=%d", 'totalItems' => CartProduct::getCountCartProducts()); $pager =& Pager::factory($pagerOptions); list($from, $to) = $pager->getOffsetByPageId(); $items = CartProduct::getAllCartProducts($from, 20); $this->smarty->assign('pager_links', $pager->links); $this->smarty->assign('page_numbers', array('current' => $pager->getCurrentPageID(), 'total' => $pager->numPages())); $this->smarty->assign('products', $items); return $this->smarty->fetch('admin/products.tpl'); break; case 'categories': require_once 'include/CartCategory.php'; error_reporting(E_ALL); switch (@$_REQUEST['action']) { case 'addedit': $category = new CartCategory(@$_REQUEST['cartcategory_categories_id']); $form = $category->getAddEditForm(); if (!$form->validate() || !$form->isSubmitted() || !isset($_REQUEST['cartcategory_submit'])) { return $form->display(); } break; case 'delete': $category = new CartCategory(@$_REQUEST['cartcategory_categories_id']); $category->delete(); break; } $this->smarty->assign('categories', CartCategory::getCartCategorys(array('parent_id' => 0))); return $this->smarty->fetch('admin/categories.tpl'); break; case 'product_types': require_once 'include/CartProductType.php'; error_reporting(E_ALL); switch (@$_REQUEST['action']) { case 'addedit': $productType = new CartProductType(@$_REQUEST['cartproducttype_type_id']); $form = $productType->getAddEditForm(); if (!$form->validate() || !$form->isSubmitted() || !isset($_REQUEST['cartproducttype_submit'])) { return $form->display(); } break; case 'delete': $productType = new CartProductType(@$_REQUEST['cartproducttype_type_id']); $productType->delete(); break; } $this->smarty->assign('productTypes', CartProductType::getAllCartProductTypes()); return $this->smarty->fetch('admin/product_types.tpl'); break; case 'shipping': require_once 'include/CartShippingRate.php'; $this->addJS('/modules/Cart/js/cartEvent.js'); switch (@$_REQUEST['action']) { case 'addedit': $rate = new CartShippingRate(@$_REQUEST['cartshippingrate_id']); $form = $rate->getAddEditForm(); if (!$form->validate() || !isset($_REQUEST['cartshippingrate_submit'])) { return $form->display(); } break; case 'delete': $rate = new CartShippingRate(@$_REQUEST['cartshippingrate_id']); $rate->delete(); break; } $rates = CartShippingRate::getAllCartShippingRates(); $this->smarty->assign('rates', $rates); return $this->smarty->fetch('admin/shippingrates.tpl'); break; case 'tax_classes': require_once 'include/CartTaxClass.php'; switch (@$_REQUEST['action']) { case 'addedit': $class = new CartTaxClass(@$_REQUEST['carttaxclass_tax_class_id']); $form = $class->getAddEditForm(); if (!$form->validate() || !isset($_REQUEST['carttaxclass_submit'])) { return $form->display(); } break; case 'delete': $class = new CartTaxClass(@$_REQUEST['carttaxclass_tax_class_id']); $class->delete(); break; } $classes = CartTaxClass::getAllCartTaxClasses(); $this->smarty->assign('taxclasses', $classes); return $this->smarty->fetch('admin/taxclasses.tpl'); break; case 'tax_rates': require_once 'include/CartTaxRate.php'; switch (@$_REQUEST['action']) { case 'addedit': $rate = new CartTaxRate(@$_REQUEST['carttaxrate_tax_rates_id']); $form = $rate->getAddEditForm(); if (!$form->validate() || !isset($_REQUEST['carttaxrate_submit'])) { return $form->display(); } break; case 'delete': $rate = new CartTaxRate(@$_REQUEST['carttaxrate_tax_rates_id']); $rate->delete(); break; } $rates = CartTaxRate::getAllCartTaxRates(); $this->smarty->assign('taxrates', $rates); return $this->smarty->fetch('admin/taxrates.tpl'); break; case 'manufacturers': require_once 'include/CartManufacturer.php'; switch (@$_REQUEST['action']) { case 'addedit': $man = new CartManufacturer(@$_REQUEST['cartmanufacturer_manufacturers_id']); $form = $man->getAddEditForm(); if (!isset($_REQUEST['cartmanufacturer_submit'])) { return $form->display(); } break; case 'delete': $man = new CartManufacturer(@$_REQUEST['cartmanufacturer_manufacturers_id']); $man->delete(); break; } $manufacturers = CartManufacturer::getAllCartManufacturers(); $this->smarty->assign('manufacturers', $manufacturers); return $this->smarty->fetch('admin/manufacturers.tpl'); break; case 'orders': require_once 'include/CartOrder.php'; $this->addCSS('/modules/Cart/css/cart.css'); $this->addJS('/modules/Cart/js/cart.js'); switch (@$_REQUEST['action']) { case 'addedit': $order = new CartOrder(@$_REQUEST['cartorder_orders_id']); $form = $order->getAddEditForm(); if (!$form->validate() || !isset($_REQUEST['cartorder_submit'])) { return $form->display(); } break; case 'delete': $order = new CartOrder(@$_REQUEST['cartorder_orders_id']); $order->delete(); break; case 'details': $order = new CartOrder(@$_REQUEST['cartorder_orders_id']); $this->smarty->assign('order', $order); return $this->smarty->fetch('admin/order_details.tpl'); break; } $orders = CartOrder::getAllCartOrders(); $this->smarty->assign('orders', $orders); return $this->smarty->fetch('admin/orders.tpl'); break; default: require_once 'include/CartCategory.php'; require_once 'include/CartProduct.php'; $cats = CartCategory::getCartCategorys(); $prods = CartProduct::getCountCartProducts(); $this->smarty->assign('categories', $cats); $this->smarty->assign('products', $prods); return $this->smarty->fetch('admin/dashboard.tpl'); break; } }