public function test_it_can_activate_a_language() { $LanguageManager = new LanguagesManager(new \DvsLanguage()); $LanguageManager->modifyActiveFlag($id = 31, $isActive = true); // the active flag should be true now... assertEquals(true, \DvsLanguage::find(31)->active); }
function loadBySlug($slug) { if ($this->getRegisteredByID($slug)) { return; } $category = db_phquery_fetch(DBRFETCH_ASSOC, 'SELECT * FROM ?#CATEGORIES_TABLE WHERE slug=?', $slug); LanguagesManager::ml_fillFields($this->__db_table, $category); $this->loadFromArray($category); }
/** * @return array */ function cartGetCartContent() { $cart_content = array(); $total_price = 0; $freight_cost = 0; $variants = ''; $currencyEntry = Currency::getSelectedCurrencyInstance(); $customerEntry = Customer::getAuthedInstance(); if (!is_null($customerEntry)) { //get cart content from the database $q = db_phquery(' SELECT t3.*, t1.itemID, t1.Quantity, t1.sample, t4.thumbnail FROM ?#SHOPPING_CARTS_TABLE t1 LEFT JOIN ?#SHOPPING_CART_ITEMS_TABLE t2 ON t1.itemID=t2.itemID LEFT JOIN ?#PRODUCTS_TABLE t3 ON t2.productID=t3.productID LEFT JOIN ?#PRODUCT_PICTURES t4 ON t3.default_picture=t4.photoID WHERE customerID=?', $customerEntry->customerID); while ($cart_item = db_fetch_assoc($q)) { // get variants $variants = GetConfigurationByItemId($cart_item["itemID"]); LanguagesManager::ml_fillFields(PRODUCTS_TABLE, $cart_item); if (isset($cart_item["sample"]) && $cart_item["sample"] == 1) { $q_sample_price = db_phquery('SELECT sample_price FROM SC_categories WHERE categoryID=(SELECT categoryID FROM SC_products WHERE productID=?)', $cart_item["productID"]); $sample_price = db_fetch_assoc($q_sample_price); $costUC = $sample_price["sample_price"]; $quantity = 1; $free_shipping = 1; } else { $costUC = GetPriceProductWithOption($variants, $cart_item["productID"]); $quantity = $cart_item["Quantity"]; $free_shipping = $cart_item["free_shipping"]; } $tmp = array("productID" => $cart_item["productID"], "slug" => $cart_item["slug"], "id" => $cart_item["itemID"], "name" => $cart_item["name"], 'thumbnail_url' => $cart_item['thumbnail'] && file_exists(DIR_PRODUCTS_PICTURES . '/' . $cart_item['thumbnail']) ? URL_PRODUCTS_PICTURES . '/' . $cart_item['thumbnail'] : '', "brief_description" => $cart_item["brief_description"], "quantity" => $quantity, "free_shipping" => $free_shipping, "costUC" => $costUC, "product_priceWithUnit" => show_price($costUC), "cost" => show_price($quantity * $costUC), "product_code" => $cart_item["product_code"]); if ($tmp['thumbnail_url']) { list($thumb_width, $thumb_height) = getimagesize(DIR_PRODUCTS_PICTURES . '/' . $cart_item['thumbnail']); list($tmp['thumbnail_width'], $tmp['thumbnail_height']) = shrink_size($thumb_width, $thumb_height, round(CONF_PRDPICT_THUMBNAIL_SIZE / 2), round(CONF_PRDPICT_THUMBNAIL_SIZE / 2)); } $freight_cost += $cart_item["Quantity"] * $cart_item["shipping_freight"]; $strOptions = GetStrOptions(GetConfigurationByItemId($tmp["id"])); if (trim($strOptions) != "") { $tmp["name"] .= " (" . $strOptions . ")"; } if (isset($cart_item["sample"]) && $cart_item["sample"] == 1) { $tmp["name"] .= " [SAMPLE]"; } if ($cart_item["min_order_amount"] > $cart_item["Quantity"]) { $tmp["min_order_amount"] = $cart_item["min_order_amount"]; } if ($cart_item["min_order_amount"] > 1 && $cart_item["Quantity"] % $cart_item["min_order_amount"] != 0) { $tmp["multiplicity"] = $cart_item["min_order_amount"]; } if (isset($cart_item["sample"]) && $cart_item["sample"] == 1) { unset($tmp["min_order_amount"]); unset($tmp["multiplicity"]); $tmp["sample"] = 1; } $total_price += $quantity * $costUC; $cart_content[] = $tmp; } } else { //unauthorized user - get cart from session vars $total_price = 0; //total cart value $cart_content = array(); //shopping cart items count if (isset($_SESSION["gids"])) { for ($j = 0; $j < count($_SESSION["gids"]); $j++) { if ($_SESSION["gids"][$j]) { $session_items[] = CodeItemInClient($_SESSION["configurations"][$j], $_SESSION["gids"][$j]); $q = db_phquery("SELECT t1.*, p1.thumbnail FROM ?#PRODUCTS_TABLE t1 LEFT JOIN ?#PRODUCT_PICTURES p1 ON t1.default_picture=p1.photoID WHERE t1.productID=?", $_SESSION["gids"][$j]); if ($r = db_fetch_row($q)) { LanguagesManager::ml_fillFields(PRODUCTS_TABLE, $r); if (isset($_SESSION["sample"][$j]) && $_SESSION["sample"][$j] == 1) { $q_sample_price = db_phquery('SELECT sample_price FROM SC_categories WHERE categoryID=(SELECT categoryID FROM SC_products WHERE productID=?)', $_SESSION["gids"][$j]); $sample_price = db_fetch_assoc($q_sample_price); $costUC = $sample_price["sample_price"]; $quantity = 1; $free_shipping = 1; } else { $costUC = GetPriceProductWithOption($_SESSION["configurations"][$j], $_SESSION["gids"][$j]); $quantity = $_SESSION["counts"][$j]; $free_shipping = $r["free_shipping"]; } $id = $_SESSION["gids"][$j]; if (count($_SESSION["configurations"][$j]) > 0) { for ($tmp1 = 0; $tmp1 < count($_SESSION["configurations"][$j]); $tmp1++) { $id .= "_" . $_SESSION["configurations"][$j][$tmp1]; } } $tmp = array("productID" => $_SESSION["gids"][$j], "slug" => $r['slug'], "id" => $id, "name" => $r['name'], 'thumbnail_url' => $r['thumbnail'] && file_exists(DIR_PRODUCTS_PICTURES . '/' . $r['thumbnail']) ? URL_PRODUCTS_PICTURES . '/' . $r['thumbnail'] : '', "brief_description" => $r["brief_description"], "quantity" => $quantity, "free_shipping" => $free_shipping, "costUC" => $costUC, "product_priceWithUnit" => show_price($costUC), "cost" => show_price($costUC * $quantity)); if ($tmp['thumbnail_url']) { list($thumb_width, $thumb_height) = getimagesize(DIR_PRODUCTS_PICTURES . '/' . $r['thumbnail']); list($tmp['thumbnail_width'], $tmp['thumbnail_height']) = shrink_size($thumb_width, $thumb_height, round(CONF_PRDPICT_THUMBNAIL_SIZE / 2), round(CONF_PRDPICT_THUMBNAIL_SIZE / 2)); } $strOptions = GetStrOptions($_SESSION["configurations"][$j]); if (trim($strOptions) != "") { $tmp["name"] .= " (" . $strOptions . ")"; } if (isset($_SESSION["sample"][$j]) && $_SESSION["sample"][$j] == 1) { $tmp["name"] .= " [SAMPLE]"; } $q_product = db_query("select min_order_amount, shipping_freight from " . PRODUCTS_TABLE . " where productID=" . $_SESSION["gids"][$j]); $product = db_fetch_row($q_product); if ($product["min_order_amount"] > $_SESSION["counts"][$j]) { $tmp["min_order_amount"] = $product["min_order_amount"]; } if ($product["min_order_amount"] > 1 && $_SESSION["counts"][$j] % $product["min_order_amount"] != 0) { $tmp["multiplicity"] = $product["min_order_amount"]; } if (isset($_SESSION["sample"][$j]) && $_SESSION["sample"][$j] == 1) { unset($tmp["min_order_amount"]); unset($tmp["multiplicity"]); $tmp["sample"] = 1; } $freight_cost += $_SESSION["counts"][$j] * $product["shipping_freight"]; $cart_content[] = $tmp; if (isset($_SESSION["sample"][$j]) && $_SESSION["sample"][$j] == 1) { $q_sample_price = db_phquery('SELECT sample_price FROM SC_categories WHERE categoryID=(SELECT categoryID FROM SC_products WHERE productID=?)', $_SESSION["gids"][$j]); $sample_price = db_fetch_assoc($q_sample_price); $total_price += $sample_price["sample_price"]; } else { $total_price += GetPriceProductWithOption($_SESSION["configurations"][$j], $_SESSION["gids"][$j]) * $_SESSION["counts"][$j]; } } } } } } return array("cart_content" => $cart_content, "total_price" => $total_price, "freight_cost" => $freight_cost); }
/** * @param int $orderID * @param array $shipping_info - ('countryID','zoneID', 'zip') * @param array $billing_info - ('countryID','zoneID', 'zip') */ function saveToOrderedCarts($orderID, $shipping_info, $billing_info, $calculate_tax = true) { $sql = "DELETE FROM ?#ORDERED_CARTS_TABLE WHERE orderID=?"; db_phquery($sql, $orderID); $r_aItem = $this->Items->getChildNodes('item'); $tc = count($r_aItem); for ($i = 0; $i < $tc; $i++) { $aItem =& $r_aItem[$i]; /* @var $aItem xmlNodeX */ $aProduct =& $aItem->getFirstChildByName('product'); $productID = $aProduct->attribute('id'); db_phquery('INSERT ?#SHOPPING_CART_ITEMS_TABLE (productID) VALUES(?)', $productID); $aItem->attribute('id', db_insert_id(SHOPPING_CART_ITEMS_TABLE)); //if(strpos($aItem->attribute('id'), '_') !== false){ // db_phquery('INSERT ?#SHOPPING_CART_ITEMS_TABLE (productID) VALUES(?)',$productID); // $aItem->attribute('id', db_insert_id(SHOPPING_CART_ITEMS_TABLE)); $aVariants =& $aItem->getFirstChildByName('variants'); $r_aVariant = $aVariants->getChildrenByName('variant'); foreach ($r_aVariant as $aVariant) { /* @var $aVariant xmlNodeX */ db_phquery('INSERT ?#SHOPPING_CART_ITEMS_CONTENT_TABLE (itemID, variantID) VALUES(?,?)', $aItem->attribute('id'), $aVariant->attribute('id')); } //} $dbq = ' SELECT ' . LanguagesManager::sql_prepareField('name') . ' AS name, product_code, categoryID FROM ?#PRODUCTS_TABLE WHERE productID=? '; $q_product = db_phquery($dbq, $productID); $product = db_fetch_row($q_product); $productComplexName = ''; $aVariants =& $aItem->getFirstChildByName('variants'); $r_aVariant = $aVariants->getChildrenByName('variant'); $variants = array(); foreach ($r_aVariant as $aVariant) { /* @var $aVariant xmlNodeX */ $variants[] = $aVariant->attribute('id'); } $options = GetStrOptions($variants); if ($options != "") { $productComplexName = $product["name"] . " (" . $options . ")"; } else { $productComplexName = $product["name"]; } if ($product["product_code"]) { $productComplexName = "[" . $product["product_code"] . "] " . $productComplexName; } $price = GetPriceProductWithOption($variants, $productID); if ($aItem->getChildData('sample')) { $productComplexName .= " [SAMPLE]"; $q_sample_price = db_phquery('SELECT sample_price FROM SC_categories WHERE categoryID=(SELECT categoryID FROM SC_products WHERE productID=?)', $productID); $sample_price = db_fetch_assoc($q_sample_price); $price = $sample_price["sample_price"]; $quantity = 1; } else { $quantity = $aItem->getChildData('quantity'); } $tax = $calculate_tax ? taxCalculateTax2($productID, $shipping_info, $billing_info) : 0; $dbq = ' INSERT ?#ORDERED_CARTS_TABLE (itemID, orderID, name, Price, Quantity, tax ) VALUES (?, ?, ?, ?, ?, ?) '; db_phquery($dbq, $aItem->attribute('id'), $orderID, $productComplexName, $price, $quantity, $tax); $q = db_phquery('SELECT statusID FROM ?#ORDERS_TABLE WHERE orderID=?', $orderID); $order = db_fetch_row($q); if ($order["statusID"] != ostGetCanceledStatusId() && CONF_CHECKSTOCK) { $dbq = ' UPDATE ?#PRODUCTS_TABLE SET in_stock=in_stock-' . xEscapeSQLstring($quantity) . ' WHERE productID=? '; db_phquery($dbq, $productID); } } }
$row = db_fetch_row($q); if ($row) { if (!file_exists(DIR_PRODUCTS_PICTURES . "/" . $row[3])) { $row[3] = ""; } $smarty->assign("selected_category", $row); } //calculate a path to the category $smarty->assign("product_category_path", catCalculatePathToCategory($categoryID)); //reviews number $k = db_phquery_fetch(DBRFETCH_FIRST, "SELECT count(*) FROM ?#DISCUSSIONS_TABLE WHERE productID=?", $productID); //extra parameters $extra = GetExtraParametrs($productID); //related items $related = array(); $related_records = db_phquery_fetch(DBRFETCH_ROW_ALL, 'SELECT pr.productID as productID, ' . LanguagesManager::sql_prepareField('name') . ' AS name, Price, slug FROM ?#PRODUCTS_TABLE AS pr JOIN ?#RELATED_PRODUCTS_TABLE AS rel ON (rel.`productID` = pr.`productID`) WHERE Owner=? AND enabled = 1', $productID); foreach ($related_records as $r) { $r[2] = show_price($r[2]); $RelatedPictures = GetPictures($r['productID']); foreach ($RelatedPictures as $_RelatedPicture) { if (!$_RelatedPicture['default_picture']) { continue; } if (!file_exists(DIR_PRODUCTS_PICTURES . "/" . $_RelatedPicture['thumbnail'])) { break; } $r['pictures'] = array('default' => $_RelatedPicture); break; } $related[] = $r; }