function getProductBySku($sku) { global $database, $logger; $logger->debug(get_class($this) . "::getProductBySku({$sku})"); $prod = new Product(); $ps_prod = new ps_product(); $ps_cat = new ps_product_category(); $query = "select product_id from #__vm_product where product_sku=" . $sku; $database->loadQuery($query); $id = $db->loadResult(); $prod->setOid($id); $prod->setName($ps_prod->get_field('product_name')); $prod->setFlypage($ps_prod->get_flypage($id)); $prod->setCategoryId($ps_cat->get_cid($id)); return $prod; }
/** * Calculates the taxable order subtotal for the order. * If an item has no weight, it is non taxable. * @author Chris Coleman * @param array $d * @return float Subtotal */ function calc_order_taxable($d) { $auth = $_SESSION['auth']; $cart = $_SESSION['cart']; $subtotal = 0.0; require_once CLASSPATH . 'ps_product.php'; $ps_product = new ps_product(); require_once CLASSPATH . 'ps_shipping_method.php'; $db = new ps_DB(); for ($i = 0; $i < $cart["idx"]; $i++) { $skip_tax = false; // do we skip this product due to zero percent tax rate? $tax_rate_id = $ps_product->get_field($cart[$i]["product_id"], 'product_tax_id'); if ($tax_rate_id != '0') { // look up the tax rate $q = "SELECT tax_rate FROM #__{vm}_tax_rate WHERE tax_rate_id='{$tax_rate_id}'"; $db->query($q); if ($db->num_rows() > 0) { $tax_rate = $db->f('tax_rate'); if ($tax_rate == 0) { $skip_tax = true; } } } $price = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]); $product_price = $GLOBALS['CURRENCY']->convert($price["product_price"], $price['product_currency']); $item_weight = ps_shipping_method::get_weight($cart[$i]["product_id"]) * $cart[$i]['quantity']; if (($item_weight != 0 or TAX_VIRTUAL == '1') && !$skip_tax) { $subtotal += $product_price * $cart[$i]["quantity"]; } } return $subtotal; }
/** * Retrieves the maximum and minimum quantity for the product specified by $product_id * * @param int $product_id * @return array */ function product_order_levels($product_id) { $min_order = 0; $max_order = 0; $product_order_levels = ps_product::get_field($product_id, 'product_order_levels'); $product_parent_id = ps_product::get_field($product_id, 'product_parent_id'); if ($product_order_levels != ',') { $order_levels = $product_order_levels; $levels = explode(",", $order_levels); $min_order = array_shift($levels); $max_order = array_shift($levels); } else { if ($product_parent_id > 0) { //check parent if product_parent_id != 0 $product_order_levels = ps_product::get_field($product_parent_id, 'product_order_levels'); $product_parent_id = ps_product::get_field($product_parent_id, 'product_parent_id'); if ($product_order_levels != ",") { $order_levels = $product_order_levels; $levels = explode(",", $order_levels); $min_order = array_shift($levels); $max_order = array_shift($levels); } } } return array($min_order, $max_order); }
$tax_total = 0; $shipping_total = $shipping_tax = 0; $order_total = 0; $coupon_discount = vmGet($_SESSION, 'coupon_discount', 0); $coupon_discount_before = $coupon_discount_after = $payment_discount_before = $payment_discount_after = $tax = $shipping = false; $product_rows = array(); for ($i = 0; $i < $cart["idx"]; $i++) { // Added for the zone shipping module $vars["zone_qty"] += $cart[$i]["quantity"]; if ($i % 2) { $product_rows[$i]['row_color'] = "sectiontableentry2"; } else { $product_rows[$i]['row_color'] = "sectiontableentry1"; } // 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 . basename($_SERVER['PHP_SELF']) . "?page=shop.product_details&flypage={$flypage}&product_id={$product_parent_id}"); } else { $url = $sess->url(URL . basename($_SERVER['PHP_SELF']) . "?page=shop.product_details&flypage={$flypage}&product_id=" . $_SESSION['cart'][$i]["product_id"]); } $product_rows[$i]['product_name'] = "<a href=\"{$url}\"><strong>" . shopMakeHtmlSafe($ps_product->get_field($_SESSION['cart'][$i]["product_id"], "product_name")) . "</strong></a><br />" . $ps_product->getDescriptionWithTax($_SESSION['cart'][$i]["description"], $_SESSION['cart'][$i]["product_id"]); // Display attribute values if this an item $product_rows[$i]['product_attributes'] = ""; if ($product_parent_id) { $db_detail = $ps_product->attribute_sql($cart[$i]["product_id"], $product_parent_id); while ($db_detail->next_record()) { $product_rows[$i]['product_attributes'] .= "<br />" . $db_detail->f("attribute_name") . " ";
/** * Called to validate the form values before the order is stored * * @author gday * @author soeren * * @param array $d * @return boolean */ function validate_form(&$d) { global $VM_LANG, $PSHOP_SHIPPING_MODULES, $vmLogger; $db = new ps_DB(); $auth = $_SESSION['auth']; $cart = $_SESSION['cart']; if (!$cart["idx"]) { $q = "SELECT order_id FROM #__{vm}_orders WHERE user_id='" . $auth["user_id"] . "' "; $q .= "ORDER BY cdate DESC"; $db->query($q); $db->next_record(); $d["order_id"] = $db->f("order_id"); return False; } if (PSHOP_AGREE_TO_TOS_ONORDER == '1') { if (empty($d["agreed"])) { $vmLogger->warning($VM_LANG->_('PHPSHOP_AGREE_TO_TOS', false)); return false; } } if (!ps_checkout::noShippingMethodNecessary()) { if (!$this->validate_shipping_method($d)) { return False; } } if (!$this->validate_payment_method($d, false)) { return false; } if (CHECK_STOCK == '1') { for ($i = 0; $i < $cart["idx"]; $i++) { $quantity_in_stock = ps_product::get_field($cart[$i]["product_id"], 'product_in_stock'); $product_name = ps_product::get_field($cart[$i]["product_id"], 'product_name'); if ($cart[$i]["quantity"] > $quantity_in_stock) { $vmLogger->err('The Quantity for the Product "' . $product_name . '" in your Cart (' . $cart[$i]["quantity"] . ') exceeds the Quantity in Stock (' . $quantity_in_stock . '). We are very sorry for this Inconvenience, but you you need to lower the Quantity in Cart for this Product.'); return false; } } } // calculate the unix timestamp for the specified expiration date // default the day to the 1st $expire_timestamp = @mktime(0, 0, 0, $_SESSION["ccdata"]["order_payment_expire_month"], 15, $_SESSION["ccdata"]["order_payment_expire_year"]); $_SESSION["ccdata"]["order_payment_expire"] = $expire_timestamp; return True; }
/** * Creates the Quantity Input Boxes/Radio Buttons/Lists for Products * * @param int $product_id The Parent Product ID * @param int $prod_id The actual Product ID * @param string $child * @param string $use_parent * @return string */ function show_quantity_box($product_id, $prod_id, $child = false, $use_parent = 'N') { global $VM_LANG; $tpl = vmTemplate::getInstance(); if ($child == 'Y') { //We have a child list so get the current quantity; $quantity = 0; for ($i = 0; $i < $_SESSION["cart"]["idx"]; $i++) { if ($_SESSION['cart'][$i]["product_id"] == $prod_id) { $quantity = $_SESSION['cart'][$i]["quantity"]; } } } else { $quantity = vmrequest::getInt('quantity', 1); } // Detremine which style to use if ($use_parent == 'Y' && !empty($product_id)) { $id = $product_id; } else { $id = $prod_id; } //Get style to use $product_in_stock = ps_product::get_field($id, 'product_in_stock'); $quantity_options = ps_product::get_quantity_options($id); extract($quantity_options); //Start output of quantity //Check for incompatabilities and reset to normal if (CHECK_STOCK == '1' && !$product_in_stock) { $display_type = 'hide'; } if (empty($display_type) || @$display_type == "hide" && $child == 'Y' || @$display_type == "radio" && $child == 'YM' || @$display_type == "radio" && !$child) { $display_type = "none"; } unset($quantity_options['display_type']); $tpl->set('prod_id', $prod_id); $tpl->set('quantity', $quantity); $tpl->set('display_type', $display_type); $tpl->set('child', $child); $tpl->set('quantity_options', $quantity_options); //Determine if label to be used $html = $tpl->fetch('product_details/includes/quantity_box_general.tpl.php'); return $html; }
function getCartnvpstr(&$order_totals = array()) { global $auth, $VM_LANG; $cart = $_SESSION['cart']; require_once CLASSPATH . 'ps_product.php'; $ps_product = new ps_product(); $ret_str = ""; $item_total = 0; for ($i = 0; $i < $cart["idx"]; $i++) { // Product PRICE $price = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]); // Convert to product currency if necessary $product_price = $GLOBALS['CURRENCY']->convert($price["product_price"], $price["product_currency"]); // SUBTOTAL CALCULATION $ret_str .= "&L_AMT" . $i . "=" . round($product_price, 2); $ret_str .= "&L_QTY" . $i . "=" . $cart[$i]["quantity"]; $ret_str .= "&L_NAME" . $i . "=" . urlencode($ps_product->get_field($_SESSION['cart'][$i]["product_id"], "product_name")); $item_total += round($product_price, 2) * $cart[$i]["quantity"]; } if (!empty($order_totals['coupon_discount'])) { // Discount is the difference left after order total has been reduced by subtotal, tax, shipping and shipping tax $discount = round($order_totals['order_total'], 2) - $item_total - round($order_totals['order_tax'], 2) - $order_totals['order_shipping'] - $order_totals['order_shipping_tax']; // add discount as line item $ret_str .= "&L_AMT" . $i . "=" . round($discount, 2); $ret_str .= "&L_QTY" . $i . "=1"; $ret_str .= "&L_NAME" . $i . "=" . urlencode($VM_LANG->_('PHPSHOP_COUPON_DISCOUNT')); $item_total += $discount; } $order_totals['item_total'] = round($item_total, 2); $ret_str .= "&ITEMAMT=" . round($item_total, 2); //die( $ret_str ); return $ret_str; }
function notify_list($product_id) { global $sess, $mosConfig_fromname, $VM_LANG; $option = vmGet($_REQUEST, 'option'); $product_id = intval($product_id); if ($product_id == 0) { return False; } $dbv = new ps_DB(); $qt = "SELECT contact_email from #__{vm}_vendor "; $qt .= "WHERE vendor_id='1'"; $dbv->query($qt); $dbv->next_record(); $from_email = $dbv->f("contact_email"); $db = new ps_DB(); $q = 'SELECT notify_email FROM #__{vm}_waiting_list WHERE '; $q .= 'notified="0" AND product_id=' . $product_id; $db->query($q); require_once CLASSPATH . 'ps_product.php'; $ps_product = new ps_product(); while ($db->next_record()) { // get the product name for the e-mail $product_name = $ps_product->get_field($product_id, "product_name"); // lets make the e-mail up from the info we have $notice_subject = sprintf($VM_LANG->_('PRODUCT_WAITING_LIST_EMAIL_SUBJECT'), $product_name); $flypage = $ps_product->get_flypage($product_id); // now get the url information $url = URL . "index.php?page=shop.product_details&flypage={$flypage}&product_id={$product_id}&option={$option}&Itemid=" . $sess->getShopItemid(); $notice_body = sprintf($VM_LANG->_('PRODUCT_WAITING_LIST_EMAIL_TEXT'), $product_name, $url); // send the e-mail $shopper_email = $db->f("notify_email"); vmMail($from_email, $mosConfig_fromname, $shopper_email, $notice_subject, $notice_body, ""); $this->update($shopper_email, $product_id); } return True; }
/** * updates the quantity of a product_id in the cart * @author pablo * @param array $d * @return boolean result of the update */ function update(&$d) { global $VM_LANG, $vmLogger, $func, $page; include_class("product"); $product_id = (int) $d["prod_id"]; $quantity = isset($d["quantity"]) ? (int) $d["quantity"] : 1; $_SESSION['last_page'] = "shop.cart"; // Check for negative quantity if ($quantity < 0) { $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_NEGATIVE', false)); return False; } if (!is_numeric($quantity)) { $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_VALID_QUANTITY', false)); return False; } if (!$product_id) { return false; } $deleted_prod = 0; $updated_prod = 0; if ($quantity == 0 && strtolower($func) == "cartupdate") { $deleted_prod = $this->delete($d); } else { for ($i = 0; $i < $_SESSION['cart']["idx"]; $i++) { // modified for the advanced attribute modification if ($_SESSION['cart'][$i]["product_id"] == $product_id && $_SESSION['cart'][$i]["description"] == $d["description"]) { if (strtolower($func) == 'cartadd') { $quantity += $_SESSION['cart'][$i]["quantity"]; } // Get min and max order levels list($min, $max) = ps_product::product_order_levels($product_id); if ($min != 0 && $quantity < $min) { eval("\$msg = \"" . $VM_LANG->_('VM_CART_MIN_ORDER', false) . "\";"); $vmLogger->warning($msg); return false; } if ($max != 0 && $quantity > $max) { eval("\$msg = \"" . $VM_LANG->_('VM_CART_MAX_ORDER', false) . "\";"); $vmLogger->warning($msg); return false; } $quantity_options = ps_product::get_quantity_options($product_id); if (!empty($quantity_options) && !empty($quantity_options['quantity_step'])) { if ($quantity % $quantity_options['quantity_step'] > 0) { continue; } } // Remove deleted or unpublished products from the cart if (!ps_product::product_exists($product_id)) { $this->delete(array('product_id', $product_id)); continue; } // Check to see if checking stock quantity if (CHECK_STOCK) { $product_in_stock = ps_product::get_field($product_id, 'product_in_stock'); if (empty($product_in_stock)) { $product_in_stock = 0; } if ($quantity > $product_in_stock) { global $notify; $_SESSION['notify'] = array(); $_SESSION['notify']['idx'] = 0; $k = 0; $notify = $_SESSION['notify']; $_SESSION['notify'][$k]["prod_id"] = $product_id; $_SESSION['notify'][$k]["quantity"] = $quantity; $_SESSION['notify']['idx']++; $page = 'shop.waiting_list'; return true; } } $_SESSION['cart'][$i]["quantity"] = $quantity; $updated_prod++; } } } if (!empty($_SESSION['coupon_discount'])) { // Update the Coupon Discount !! require_once CLASSPATH . 'ps_coupon.php'; ps_coupon::process_coupon_code($d); } ps_cart::saveCart(); return array($updated_prod, $deleted_prod); }
// Determiine the cart direction and set vars if (@$_SESSION['vmCartDirection']) { $i = 0; $up_limit = $cart["idx"]; } else { $i = $cart["idx"] - 1; $up_limit = -1; } $ci = 0; //Start loop through cart do { //If we are not showing the minicart start the styling of the individual products $price = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]); $price["product_price"] = $GLOBALS['CURRENCY']->convert($price["product_price"], $price["product_currency"]); $amount += $cart[$i]["quantity"]; $product_parent_id = $ps_product->get_field($cart[$i]["product_id"], "product_parent_id"); if (@$auth["show_price_including_tax"] == 1) { $my_taxrate = $ps_product->get_product_taxrate($cart[$i]["product_id"]); $price["product_price"] *= $my_taxrate + 1; } $subtotal = round($price["product_price"], 2) * $cart[$i]["quantity"]; $total += $subtotal; $flypage_id = $product_parent_id; if ($flypage_id == 0) { $flypage_id = $cart[$i]["product_id"]; } $flypage = $ps_product->get_flypage($flypage_id); $category_id = vmGet($cart[$i], 'category_id', 0); if ($product_parent_id) { $url = $sess->url(URL . "index.php?page=shop.product_details&flypage={$flypage}&product_id={$product_parent_id}&category_id={$category_id}"); } else {