/** * Indique si un produit a déajà été acheté par un utilisateur * * @param integer $uid Identifiant de l'utilisateur * @param integer $productId Identifiant du produit * @return boolean Indique si c'est le cas ou pas */ function productAlreadyBought($uid = 0, $productId = 0) { if ($uid == 0) { $uid = myshop_utils::getCurrentUserID(); } $sql = 'SELECT Count(*) as cpt FROM ' . $this->db->prefix('myshop_caddy') . ' c, ' . $this->db->prefix('myshop_commands') . ' f WHERE c.caddy_product_id = ' . intval($productId) . ' AND c.caddy_cmd_id = f.cmd_id AND f.cmd_uid = ' . intval($uid); $result = $this->db->query($sql); if (!$result) { return 0; } list($count) = $this->db->fetchRow($result); if ($count > 0) { return true; } else { return false; } }
/** * Calculate Product price with discount and no Fee * * @param integer $produtId * @param float $prixHT Price without Fee * @param array $discountsDescription * @param integer $productQty */ function applyDiscountOnEachProduct($productId, &$prixHT, &$discountsDescription, $productQty) { global $h_myshop_commands; $rules = array(); $rules = $this->getRulesOnEachProduct(); // Return objects Discounts if (count($rules) > 0) { $uid = myshop_utils::getCurrentUserID(); foreach ($rules as $rule) { switch ($rule->getVar('disc_when')) { case MYSHOP_DISCOUNT_WHEN1: // All if ($rule->getVar('disc_percent_monney') == MYSHOP_DISCOUNT_TYPE1) { // Discount x pourcent $prixHT = $this->getDiscountedPrice($prixHT, $rule->getVar('disc_amount')); if ($prixHT < 0) { $prixHT = 0; } } else { // Discount x euros $prixHT -= $rule->getVar('disc_amount'); if ($prixHT < 0) { $prixHT = 0; } } $discountsDescription[] = $rule->getVar('disc_description'); break; case MYSHOP_DISCOUNT_WHEN2: // if first order if ($h_myshop_commands->isFirstCommand($uid)) { if ($rule->getVar('disc_percent_monney') == MYSHOP_DISCOUNT_TYPE1) { // Discount x percent $prixHT = $this->getDiscountedPrice($prixHT, $rule->getVar('disc_amount')); if ($prixHT < 0) { $prixHT = 0; } } else { // Discount x euros $prixHT -= $rule->getVar('disc_amount'); if ($prixHT < 0) { $prixHT = 0; } } $discountsDescription[] = $rule->getVar('disc_description'); } break; case MYSHOP_DISCOUNT_WHEN3: // first sale of product if (!$h_myshop_commands->productAlreadyBought($uid, $productId)) { if ($rule->getVar('disc_percent_monney') == MYSHOP_DISCOUNT_TYPE1) { // Discount x percent $prixHT = $this->getDiscountedPrice($prixHT, $rule->getVar('disc_amount')); if ($prixHT < 0) { $prixHT = 0; } } else { // Discount x euros $prixHT -= $rule->getVar('disc_amount'); if ($prixHT < 0) { $prixHT = 0; } } $discountsDescription[] = $rule->getVar('disc_description'); } break; case MYSHOP_DISCOUNT_WHEN4: // if quantity is =, >, >=, <, <= to ... $qtyDiscount = false; switch ($rule->getVar('disc_qty_criteria')) { case 0: // = if ($productQty == $rule->getVar('disc_qty_value')) { $qtyDiscount = true; } break; case 1: // > if ($productQty > $rule->getVar('disc_qty_value')) { $qtyDiscount = true; } break; case 2: // >= if ($productQty >= $rule->getVar('disc_qty_value')) { $qtyDiscount = true; } break; case 3: // < if ($productQty < $rule->getVar('disc_qty_value')) { $qtyDiscount = true; } break; case 4: // <= if ($productQty <= $rule->getVar('disc_qty_value')) { $qtyDiscount = true; } break; } if ($qtyDiscount) { if ($rule->getVar('disc_percent_monney') == MYSHOP_DISCOUNT_TYPE1) { // Discount x percent $prixHT = $this->getDiscountedPrice($prixHT, $rule->getVar('disc_amount')); if ($prixHT < 0) { $prixHT = 0; } } else { // Discount x euros $prixHT -= $rule->getVar('disc_amount'); if ($prixHT < 0) { $prixHT = 0; } } $discountsDescription[] = $rule->getVar('disc_description'); } break; } } } }
$url = MYSHOP_URL . 'include/myshop.css'; echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$url}\" />"; echo "</head><body>"; if (!isset($xoopsTpl)) { require_once XOOPS_ROOT_PATH . '/class/template.php'; $xoopsTpl = new XoopsTpl(); } } if (isset($_GET['stock']) && $_GET['stock'] == 'add' && myshop_utils::isMemberOfGroup(myshop_utils::getModuleOption('grp_qty'))) { $h_myshop_products->increaseStock($product); } if (isset($_GET['stock']) && $_GET['stock'] == 'substract' && myshop_utils::isMemberOfGroup(myshop_utils::getModuleOption('grp_qty'))) { $h_myshop_products->decreaseStock($product); $h_myshop_products->verifyLowStock($product); } $currentUser = myshop_utils::getCurrentUserID(); $baseurl = MYSHOP_URL . basename(__FILE__) . '?product_id=' . $product->getVar('product_id'); // Options for template $xoopsTpl->assign('baseurl', $baseurl); $xoopsTpl->assign('nostock_msg', myshop_utils::getModuleOption('nostock_msg')); $xoopsTpl->assign('mod_pref', $mod_pref); $xoopsTpl->assign('icones', $icones); $xoopsTpl->assign('canRateProducts', myshop_utils::getModuleOption('rateproducts')); $xoopsTpl->assign('mail_link', 'mailto:?subject=' . sprintf(_MYSHOP_INTARTICLE, $xoopsConfig['sitename']) . '&body=' . sprintf(_MYSHOP_INTARTFOUND, $xoopsConfig['sitename']) . ': ' . XOOPS_URL . '/modules/myshop/product.php?product_id=' . $product_id); $xoopsTpl->assign('canChangeQuantity', myshop_utils::isMemberOfGroup(myshop_utils::getModuleOption('grp_qty'))); // Group with permissions to change product quantity $xoopsTpl->assign('ProductStockQuantity', sprintf(_MYSHOP_QUANTITY_STOCK, $product->getVar('product_stock'))); // Search Category of Product $tbl_tmp = $tbl_categories = $tbl_ancestors = array(); $tbl_categories = $h_myshop_cat->getAllCategories(); $product_category = null;
/** * Retourne les produits d'un utilisateur * * @param integer $persistent_uid L'ID de l'utilisateur * @return array Tableaux d'objets de type myshop_persistent_cart */ function getUserProducts($persistent_uid = 0) { if (myshop_utils::getModuleOption('persistent_cart') == 0) { return false; } $persistent_uid = $persistent_uid == 0 ? myshop_utils::getCurrentUserID() : $persistent_uid; $criteria = new Criteria('persistent_uid', $persistent_uid, '='); return $this->getObjects($criteria); }
/** * Indique si un utilisateur a déjà voté pour un produit * * @param integer $vote_uid L'identifiant de l'utilisateur * @param integer $vote_product_id Le numéro du produit * @return boolean True s'il a déjà voté sinon False */ function hasUserAlreadyVoted($vote_uid, $vote_product_id) { if ($vote_uid == 0) { $vote_uid = myshop_utils::getCurrentUserID(); } $criteria = new CriteriaCompo(); $criteria->add(new Criteria('vote_product_id', $vote_product_id, '=')); $criteria->add(new Criteria('vote_uid', $vote_uid, '=')); return $this->getCount($criteria); }
if ($product->getVar('product_online') == 0) { myshop_utils::redirect(_MYSHOP_ERROR2, 'index.php', 5); } // product publish if (myshop_utils::getModuleOption('show_unpublished') == 0 && $product->getVar('product_submitted') > time()) { myshop_utils::redirect(_MYSHOP_ERROR3, 'index.php', 5); } // stock required if (myshop_utils::getModuleOption('nostock_display') == 0 && $product->getVar('product_stock') == 0) { if (xoops_trim(myshop_utils::getModuleOption('nostock_display')) != '') { myshop_utils::redirect(myshop_utils::getModuleOption('nostock_display'), 'index.php', 5); } } if (!empty($_POST['btnsubmit'])) { $GLOBALS['current_category'] = -1; $ratinguser = myshop_utils::getCurrentUserID(); $canRate = true; if ($ratinguser != 0) { if ($h_myshop_votedata->hasUserAlreadyVoted($ratinguser, $product->getVar('product_id'))) { $canRate = false; } } else { if (hasAnonymousAlreadyVoted('', $product->getVar('product_id'))) { $canRate = false; } } if ($canRate) { if ($_POST['rating'] == '--') { myshop_utils::redirect(_MYSHOP_NORATING, MYSHOP_URL . 'product.php?product_id=' . $product->getVar('product_id'), 4); } $rating = intval($_POST['rating']);