/** * Get all attributes for selected product. * * Each attribute has a new price. * * @param * integer idproduct * @param * integer idclient (0 by default) * @return array with attributes' product informations * @throws on error FrontendException object will be returned * @access public */ public function getAttributesForProductById($id) { $clientGroupId = Session::getActiveClientGroupid(); if (!empty($clientGroupId)) { $sql = "SELECT\n\t\t\t\t\t\tP.idproduct as id,\n\t\t\t\t\t\tPAS.stock,\n\t\t\t\t\t\tPAS.idproductattributeset,\n\t\t\t\t\t\tPAS.`value`,\n\t\t\t\t\t\tPAS.symbol,\n\t\t\t\t\t\tAT.name as availablity,\n\t\t\t\t\t\tPAS.photoid as photoid,\n\t\t\t\t\t\tPAS.symbol,\n\t\t\t\t\t\tIF(PAS.weight IS NULL, P.weight, PAS.weight) AS weight,\n\t\t\t\t\t\tPAVS.idproductattributevalueset,\n\t\t\t\t\t\tPAVS.productattributesetid AS attributesgroup,\n\t\t\t\t\t\tAPV.name AS attributename,\n\t\t\t\t\t\tAPV.idattributeproductvalue AS attributeid,\n\t\t\t\t\t\tAP.name AS attributegroupname,\n\t\t\t\t\t\tAP.idattributeproduct AS attributegroupid,\n\t\t\t\t\t\tIF(PGP.promotion = 1 AND IF(PGP.promotionstart IS NOT NULL, PGP.promotionstart <= CURDATE(), 1) AND IF(PGP.promotionend IS NOT NULL, PGP.promotionend >= CURDATE(), 1),\n\t\t\t\t\t\t\tCASE PAS.suffixtypeid\n \tWHEN 1 THEN PGP.discountprice * (PAS.value / 100)\n WHEN 2 THEN PGP.discountprice + PAS.value\n WHEN 3 THEN PGP.discountprice - PAS.value\n \tWHEN 4 THEN PAS.`value`\n END,\n\t\t\t\t\t\t\tIF(PGP.groupprice IS NULL AND P.promotion = 1 AND IF(P.promotionstart IS NOT NULL, P.promotionstart <= CURDATE(), 1) AND IF(P.promotionend IS NOT NULL, P.promotionend >= CURDATE(), 1),\n\t\t\t\t\t\t\t\tPAS.discountprice,\n\t\t\t\t\t\t\t\tIF(PGP.sellprice IS NOT NULL,\n\t\t\t\t\t\t\t\t\tCASE PAS.suffixtypeid\n\t\t \tWHEN 1 THEN PGP.sellprice * (PAS.value / 100)\n\t\t WHEN 2 THEN PGP.sellprice + PAS.value\n\t\t WHEN 3 THEN PGP.sellprice - PAS.value\n\t\t \tWHEN 4 THEN PAS.`value`\n\t \tEND,\n\t\t\t\t\t\t\t\t\tPAS.attributeprice\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) * CR.exchangerate AS attributeprice,\n\t\t\t\t\t\t(PAS.attributeprice * CR.exchangerate) AS attributepricenettobeforepromotion,\n\t\t\t\t\t\t(PAS.attributeprice * (1 + (V.value / 100)) * CR.exchangerate) AS attributepricegrossbeforepromotion,\n\t\t\t\t\t\tIF(PGP.promotion = 1 AND IF(PGP.promotionstart IS NOT NULL, PGP.promotionstart <= CURDATE(), 1) AND IF(PGP.promotionend IS NOT NULL, PGP.promotionend >= CURDATE(), 1),\n\t\t\t\t\t\t\tCASE PAS.suffixtypeid\n \tWHEN 1 THEN PGP.discountprice * (PAS.value / 100)\n WHEN 2 THEN PGP.discountprice + PAS.value\n WHEN 3 THEN PGP.discountprice - PAS.value\n \tWHEN 4 THEN PAS.`value`\n END,\n\t\t\t\t\t\t\tIF(PGP.groupprice IS NULL AND P.promotion = 1 AND IF(P.promotionstart IS NOT NULL, P.promotionstart <= CURDATE(), 1) AND IF(P.promotionend IS NOT NULL, P.promotionend >= CURDATE(), 1),\n\t\t\t\t\t\t\t\tPAS.discountprice,\n\t\t\t\t\t\t\t\tIF(PGP.sellprice IS NOT NULL,\n\t\t\t\t\t\t\t\t\tCASE PAS.suffixtypeid\n\t\t \tWHEN 1 THEN PGP.sellprice * (PAS.value / 100)\n\t\t WHEN 2 THEN PGP.sellprice + PAS.value\n\t\t WHEN 3 THEN PGP.sellprice - PAS.value\n\t\t \tWHEN 4 THEN PAS.`value`\n\t \tEND,\n\t\t\t\t\t\t\t\t\tPAS.attributeprice\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) * (1 + (V.value / 100)) * CR.exchangerate AS price\n\t FROM productattributeset AS PAS\n\t\t\t\t LEFT JOIN productattributevalueset PAVS ON PAVS.productattributesetid = PAS.idproductattributeset\n\t\t\t\t LEFT JOIN attributeproductvalue APV ON PAVS.attributeproductvalueid = APV.idattributeproductvalue\n\t\t\t\t LEFT JOIN attributeproduct AS AP ON APV.attributeproductid = AP.idattributeproduct\n\t\t\t\t LEFT JOIN availablitytranslation AT ON PAS.availablityid = AT.availablityid AND AT.languageid = :languageid\n\t\t\t\t LEFT JOIN product AS P ON PAS.productid = P.idproduct\n\t\t\t\t LEFT JOIN productgroupprice PGP ON PGP.productid = P.idproduct AND PGP.clientgroupid = :clientgroupid\n\t\t\t\t LEFT JOIN `vat` V ON P.vatid = V.idvat\n\t\t\t\t LEFT JOIN currencyrates CR ON CR.currencyfrom = P.sellcurrencyid AND CR.currencyto = :currencyto\n\t\t\t\t WHERE PAS.productid = :id AND PAS.status = 1"; } else { $sql = "SELECT\n\t\t\t\t\t\tP.idproduct as id,\n\t\t\t\t\t\tPAS.stock,\n\t\t\t\t\t\tPAS.idproductattributeset,\n\t\t\t\t\t\tPAS.`value`,\n\t\t\t\t\t\tPAS.symbol,\n\t\t\t\t\t\tAT.name as availablity,\n\t\t\t\t\t\tPAS.photoid as photoid,\n\t\t\t\t\t\tIF(PAS.weight IS NULL, P.weight, PAS.weight) AS weight,\n\t\t\t\t\t\tPAVS.idproductattributevalueset,\n\t\t\t\t\t\tPAVS.productattributesetid AS attributesgroup,\n\t\t\t\t\t\tAPV.name AS attributename,\n\t\t\t\t\t\tAPV.idattributeproductvalue AS attributeid,\n\t\t\t\t\t\tAP.name AS attributegroupname,\n\t\t\t\t\t\tAP.idattributeproduct AS attributegroupid,\n\t\t\t\t\t\tIF(P.promotion = 1 AND IF(P.promotionstart IS NOT NULL, P.promotionstart <= CURDATE(), 1) AND IF(P.promotionend IS NOT NULL, P.promotionend >= CURDATE(), 1), PAS.discountprice, PAS.attributeprice) * CR.exchangerate AS attributeprice,\n\t\t\t\t\t\tIF(P.promotion = 1 AND IF(P.promotionstart IS NOT NULL, P.promotionstart <= CURDATE(), 1) AND IF(P.promotionend IS NOT NULL, P.promotionend >= CURDATE(), 1), PAS.discountprice, PAS.attributeprice) * (1 + (V.value / 100)) * CR.exchangerate AS price,\n\t\t\t\t\t\t(PAS.attributeprice * CR.exchangerate) AS attributepricenettobeforepromotion,\n\t\t\t\t\t\t(PAS.attributeprice * (1 + (V.value / 100)) * CR.exchangerate) AS attributepricegrossbeforepromotion\n\t FROM productattributeset AS PAS\n\t\t\t\t LEFT JOIN productattributevalueset PAVS ON PAVS.productattributesetid = PAS.idproductattributeset\n\t\t\t\t LEFT JOIN attributeproductvalue APV ON PAVS.attributeproductvalueid = APV.idattributeproductvalue\n\t\t\t\t LEFT JOIN attributeproduct AS AP ON APV.attributeproductid = AP.idattributeproduct\n\t\t\t\t\tLEFT JOIN availablitytranslation AT ON PAS.availablityid = AT.availablityid AND AT.languageid = :languageid\n\t\t\t\t LEFT JOIN product AS P ON PAS.productid = P.idproduct\n\t\t\t\t LEFT JOIN `vat` V ON P.vatid = V.idvat\n\t\t\t\t LEFT JOIN currencyrates CR ON CR.currencyfrom = P.sellcurrencyid AND CR.currencyto = :currencyto\n\t\t\t\t WHERE PAS.productid = :id AND PAS.status = 1"; } $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('id', $id); $stmt->bindValue('languageid', Helper::getLanguageId()); $stmt->bindValue('currencyto', Session::getActiveCurrencyId()); if (!empty($clientGroupId)) { $stmt->bindValue('clientgroupid', $clientGroupId); } $Data = array(); try { $stmt->execute(); while ($rs = $stmt->fetch()) { $price = 0; $priceWithoutVat = 0; $attrId = $rs['idproductattributeset']; $Data[] = array('id' => $rs['id'], 'stock' => $rs['stock'], 'symbol' => $rs['symbol'], 'weight' => $rs['weight'], 'availablity' => $rs['availablity'], 'photoid' => $rs['photoid'], 'idproductattributeset' => $rs['idproductattributeset'], 'idproductattributevalueset' => $rs['idproductattributevalueset'], 'attributesgroup' => $rs['attributesgroup'], 'attributename' => $rs['attributename'], 'attributeid' => $rs['attributeid'], 'attributegroupname' => $rs['attributegroupname'], 'attributegroupid' => $rs['attributegroupid'], 'attributeprice' => $rs['attributeprice'], 'value' => $rs['value'], 'price' => $rs['price'], 'attributepricenettobeforepromotion' => $rs['attributepricenettobeforepromotion'], 'attributepricegrossbeforepromotion' => $rs['attributepricegrossbeforepromotion'], 'photos' => array('small' => (int) $rs['photoid'] > 0 ? App::getModel('gallery')->getImagePath(App::getModel('gallery')->getSmallImageById($rs['photoid'])) : '', 'normal' => (int) $rs['photoid'] > 0 ? App::getModel('gallery')->getImagePath(App::getModel('gallery')->getNormalImageById($rs['photoid'])) : '', 'large' => (int) $rs['photoid'] > 0 ? App::getModel('gallery')->getImagePath(App::getModel('gallery')->getLargeImageById($rs['photoid'])) : '', 'orginal' => (int) $rs['photoid'] > 0 ? App::getModel('gallery')->getImagePath(App::getModel('gallery')->getOrginalImageById($rs['photoid'])) : '')); } } catch (Exception $e) { throw new FrontendException($e->getMessage()); } return $Data; }
public function checkRulesCart() { $Data = array(); $condition = array(); if ($this->globalPriceWithoutVat > 0) { $clientGroupId = Session::getActiveClientGroupid(); if ($clientGroupId > 0) { $sql = "SELECT \n\t\t\t\t\t\t\tRCCG.rulescartid, \n\t\t\t\t\t\t\tRCR.ruleid, \n\t\t\t\t\t\t\tRCR.pkid, \n\t\t\t\t\t\t\tRCR.pricefrom, \n\t\t\t\t\t\t\tRCR.priceto,\n\t\t\t\t\t\t\tRCCG.suffixtypeid, \n\t\t\t\t\t\t\tRCCG.discount, \n\t\t\t\t\t\t\tRCCG.freeshipping, \n\t\t\t\t\t\t\tS.symbol,\n\t\t\t\t\t\t\tRCCG.clientgroupid,\n\t\t\t\t\t\t\tRCT.name,\n\t\t\t\t\t\t\tRCT.description\n\t\t\t\t\t\tFROM rulescartclientgroup RCCG\n\t\t\t\t\t\t\tLEFT JOIN rulescart RC ON RCCG.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN rulescarttranslation RCT ON RCT.rulescartid = RC.idrulescart AND RCT.languageid = :languageid\n\t\t\t\t\t\t\tLEFT JOIN rulescartrule RCR ON RCR.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN rulescartview RCV ON RCV.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN suffixtype S ON RCCG.suffixtypeid = S.idsuffixtype\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tRCV.viewid= :viewid\n\t\t\t\t\t\t\tAND RCCG.clientgroupid= :clientgroupid\n\t\t\t\t\t\t\tAND IF(RC.datefrom is not null, (cast(RC.datefrom as date) <= curdate()), 1)\n\t\t\t\t\t\t\tAND IF(RC.dateto is not null, (cast(RC.dateto as date)>= curdate()),1)\n\t\t\t\t\t\tORDER BY RCR.rulescartid"; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('clientgroupid', $clientGroupId); $stmt->bindValue('viewid', Helper::getViewId()); $stmt->bindValue('languageid', Helper::getLanguageId()); } else { $sql = "SELECT \n\t\t\t\t\t\t\tRCR.rulescartid, \n\t\t\t\t\t\t\tRCR.ruleid, \n\t\t\t\t\t\t\tRCR.pkid, \n\t\t\t\t\t\t\tRCR.pricefrom, \n\t\t\t\t\t\t\tRCR.priceto,\n\t\t\t\t\t\t\tRC.suffixtypeid, \n\t\t\t\t\t\t\tRC.discount, \n\t\t\t\t\t\t\tRC.freeshipping, \n\t\t\t\t\t\t\tS.symbol,\n\t\t\t\t\t\t\t'clientgroupid'=NULL as clientgroupid,\n\t\t\t\t\t\t\tRCT.name,\n\t\t\t\t\t\t\tRCT.description\n\t\t\t\t\t\tFROM rulescart RC\n\t\t\t\t\t\t\tLEFT JOIN rulescarttranslation RCT ON RCT.rulescartid = RC.idrulescart AND RCT.languageid = :languageid\n\t\t\t\t\t\t\tLEFT JOIN rulescartrule RCR ON RCR.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN rulescartview RCV ON RCV.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN suffixtype S ON RC.suffixtypeid = S.idsuffixtype\n\t \t\t\t\tWHERE\n\t \t\t\t\t\tRC.discountforall =1\n\t \t\t\t\tAND RCV.viewid= :viewid\n\t \t\t\t\tAND IF(RC.datefrom is not null, (cast(RC.datefrom as date) <= curdate()), 1)\n\t\t\t\t\t\t\tAND IF(RC.dateto is not null, (cast(RC.dateto as date)>= curdate()),1)\n\t\t\t\t\t\tORDER BY RCR.rulescartid"; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('viewid', Helper::getViewId()); $stmt->bindValue('languageid', Helper::getLanguageId()); } try { $stmt->execute(); while ($rs = $stmt->fetch()) { $rulescartid = $rs['rulescartid']; $ruleid = $rs['ruleid']; $currencySymbol = Session::getActiveCurrencySymbol(); if ($rs['symbol'] == '%') { $Data[$rulescartid]['discount'] = abs($rs['discount'] - 100) . $rs['symbol']; $type = $rs['discount'] > 100 ? 1 : 0; } else { $Data[$rulescartid]['discount'] = $rs['symbol'] . $rs['discount']; $type = $rs['symbol'] == '+' ? 1 : 0; } $Data[$rulescartid]['freeshipping'] = $rs['freeshipping']; $Data[$rulescartid]['name'] = $rs['name']; $Data[$rulescartid]['description'] = $rs['description']; switch ($ruleid) { case 9: // delivery if (isset($Data[$rulescartid][$ruleid])) { $Data[$rulescartid][$ruleid]['condition'] = $Data[$rulescartid][$ruleid]['condition'] . " " . _('TXT_OR') . " " . $this->getDeliveryToCondition($rs['pkid']); } else { $Data[$rulescartid][$ruleid] = array('is' => 0, 'ruleid' => $ruleid, 'condition' => _('TXT_DELIVERY_TYPE') . ": " . $this->getDeliveryToCondition($rs['pkid'])); } break; case 10: // paymentmethod if (isset($Data[$rulescartid][$ruleid])) { $Data[$rulescartid][$ruleid]['condition'] = $Data[$rulescartid][$ruleid]['condition'] . " " . _('TXT_OR') . " " . $this->getPaymentToCondition($rs['pkid']); } else { $Data[$rulescartid][$ruleid] = array('is' => 0, 'ruleid' => $ruleid, 'condition' => _('TXT_PAYMENT_TYPE') . ": " . $this->getPaymentToCondition($rs['pkid'])); } break; case 11: // final cart price if (isset($Data[$rulescartid][$ruleid])) { $Data[$rulescartid][$ruleid]['condition'] = $Data[$rulescartid][$ruleid]['condition'] . " " . _('TXT_OR') . " " . $rs['pricefrom']; } else { $Data[$rulescartid][$ruleid] = array('is' => 0, 'ruleid' => $ruleid, 'condition' => _('TXT_CART_VALUE_AMOUNT_EXCEED') . ": " . $rs['pricefrom'] . $currencySymbol); } break; case 12: // final cart price if (isset($Data[$rulescartid][$ruleid])) { $Data[$rulescartid][$ruleid]['condition'] = $Data[$rulescartid][$ruleid]['condition'] . " " . _('TXT_OR') . " " . $rs['priceto'] . $currencySymbol; } else { $Data[$rulescartid][$ruleid] = array('is' => 0, 'ruleid' => $ruleid, 'condition' => _('TXT_CART_VALUE_NOT_GREATER_THAN') . ": " . $rs['priceto'] . $currencySymbol); } break; case 13: // final cart price with dispatch method if (isset($Data[$rulescartid][$ruleid])) { $Data[$rulescartid][$ruleid]['condition'] = $Data[$rulescartid][$ruleid]['condition'] . " " . _('TXT_OR') . " " . $rs['pricefrom'] . $currencySymbol; } else { $Data[$rulescartid][$ruleid] = array('is' => 0, 'ruleid' => $ruleid, 'condition' => _('TXT_CART_DELIVERY_VALUE_AMOUNT') . ": " . $rs['pricefrom'] . $currencySymbol); } break; case 14: // final cart price with dispatch method if (isset($Data[$rulescartid][$ruleid])) { $Data[$rulescartid][$ruleid]['condition'] = $Data[$rulescartid][$ruleid]['condition'] . " " . _('TXT_OR') . " " . $rs['priceto'] . $currencySymbol; } else { $Data[$rulescartid][$ruleid] = array('is' => 0, 'ruleid' => $ruleid, 'condition' => _('TXT_CART_DELIVERY_VALUE_NOT_GREATER_THAN') . ": " . $rs['priceto'] . Session::getActiveCurrencySymbol()); } break; } } if (count($Data) > 0) { foreach ($Data as $rulescart => $rules) { foreach ($rules as $rule) { if (is_array($rule) && $rule['is'] == 0) { $condition[$rulescart]['conditions'][$rule['ruleid']] = $rule['condition']; } } $condition[$rulescart]['discount'] = $rules['discount']; $condition[$rulescart]['freeshipping'] = $rules['freeshipping']; $condition[$rulescart]['name'] = $rules['name']; $condition[$rulescart]['description'] = $rules['description']; $condition[$rulescart]['type'] = $type; } } else { $condition = 0; } } catch (Exception $e) { throw new FrontendException(_('ERR_RULES_CART')); } } else { $condition = 0; } return $condition; }
/** * Chcek cart rules. * If there is any rule, reduce global price. Otherwise return 0. * * @param * array client order * @return array discount (rulescartid, suffixtypeid, symbol, discount) or 0 * @access public */ public function getRulesCart($clientOrder) { $clientGroupId = Session::getActiveClientGroupid(); $Data = array(); $discount = array(); $check = true; $allRules = $this->getAllCartRules(); if (is_array($allRules) && !empty($allRules)) { foreach ($allRules as $rule) { $ruleid = $rule['idrulescart']; $ruleName = $rule['name']; $ruleDescription = $rule['description']; if ($clientGroupId > 0) { $sql = "SELECT \n\t\t\t\t\t\t\t\tRCCG.rulescartid, \n\t\t\t\t\t\t\t\tRCR.ruleid, \n\t\t\t\t\t\t\t\tRCR.pkid, \n\t\t\t\t\t\t\t\tRCR.pricefrom, \n\t\t\t\t\t\t\t\tRCR.priceto,\n\t\t\t\t\t\t\t\tRCCG.suffixtypeid, \n\t\t\t\t\t\t\t\tRCCG.discount, \n\t\t\t\t\t\t\t\tRCCG.freeshipping, \n\t\t\t\t\t\t\t\tS.symbol,\n\t\t\t\t\t\t\t\tRCCG.clientgroupid\n\t\t\t\t\t\t\tFROM rulescartclientgroup RCCG\n\t\t\t\t\t\t\tLEFT JOIN rulescart RC ON RCCG.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN rulescartrule RCR ON RCR.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN rulescartview RCV ON RCV.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN suffixtype S ON RCCG.suffixtypeid = S.idsuffixtype\n\t\t\t\t\t\t\tWHERE RCR.rulescartid = :ruleid\n\t\t\t\t\t\t AND RCV.viewid= :viewid\n\t\t\t\t\t\t\tAND RCCG.clientgroupid= :clientgroupid\n\t\t\t\t\t\t\tAND IF(RC.datefrom is not null, (cast(RC.datefrom as date) <= curdate()), 1)\n\t\t\t\t\t\t\tAND IF(RC.dateto is not null, (cast(RC.dateto as date)>= curdate()),1)"; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('clientgroupid', $clientGroupId); $stmt->bindValue('viewid', Helper::getViewId()); $stmt->bindValue('ruleid', $ruleid); } else { $sql = "SELECT \n\t\t\t\t\t\t\t\tRCR.rulescartid, \n\t\t\t\t\t\t\t\tRCR.ruleid, \n\t\t\t\t\t\t\t\tRCR.pkid, \n\t\t\t\t\t\t\t\tRCR.pricefrom, \n\t\t\t\t\t\t\t\tRCR.priceto,\n\t\t\t\t\t\t\t\tRC.suffixtypeid, \n\t\t\t\t\t\t\t\tRC.freeshipping, \n\t\t\t\t\t\t\t\tRC.discount, \n\t\t\t\t\t\t\t\tS.symbol,\n\t\t\t\t\t\t\t\t'clientgroupid' = NULL as clientgroupid\n\t\t\t\t\t\t\tFROM rulescart RC\n\t\t\t\t\t\t\tLEFT JOIN rulescartrule RCR ON RCR.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN rulescartview RCV ON RCV.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN suffixtype S ON RC.suffixtypeid = S.idsuffixtype\n\t\t \t\t\t\tWHERE RCR.rulescartid = :ruleid\n\t\t \tAND RC.discountforall =1\n\t\t \t\t\tAND RCV.viewid= :viewid\n\t\t \t\t\tAND IF(RC.datefrom is not null, (cast(RC.datefrom as date) <= curdate()), 1)\n\t\t\t\t\t\t\tAND IF(RC.dateto is not null, (cast(RC.dateto as date)>= curdate()),1)"; $stmt = Db::getInstance()->prepare($sql); $stmt->bindValue('viewid', Helper::getViewId()); $stmt->bindValue('ruleid', $ruleid); } try { $stmt->execute(); while ($rs = $stmt->fetch()) { $ruleid = $rs['ruleid']; $rulescartid = $rs['rulescartid']; switch ($ruleid) { case 9: // delivery (dispatchmethod) if (isset($Data[$rulescartid][$ruleid]) && $Data[$rulescartid][$ruleid] == 0 || !isset($Data[$rulescartid][$ruleid])) { if (isset($clientOrder['dispatchmethod']['dispatchmethodid']) && $clientOrder['dispatchmethod']['dispatchmethodid'] == $rs['pkid']) { $Data[$rulescartid][$ruleid] = 1; } else { $Data[$rulescartid][$ruleid] = 0; } } break; case 10: // paymentmethod if (isset($Data[$rulescartid][$ruleid]) && $Data[$rulescartid][$ruleid] == 0 || !isset($Data[$rulescartid][$ruleid])) { if (isset($clientOrder['payment']['idpaymentmethod']) && $clientOrder['payment']['idpaymentmethod'] == $rs['pkid']) { $Data[$rulescartid][$ruleid] = 1; } else { $Data[$rulescartid][$ruleid] = 0; } } break; case 11: // final cart price if (isset($Data[$rulescartid][$ruleid]) && $Data[$rulescartid][$ruleid] == 0 || !isset($Data[$rulescartid][$ruleid])) { if (isset($clientOrder['globalPrice']) && $clientOrder['globalPrice'] >= $rs['pricefrom']) { $Data[$rulescartid][$ruleid] = 1; } else { $Data[$rulescartid][$ruleid] = 0; } } break; case 12: // final cart price if (isset($Data[$rulescartid][$ruleid]) && $Data[$rulescartid][$ruleid] == 0 || !isset($Data[$rulescartid][$ruleid])) { if (isset($clientOrder['globalPrice']) && $clientOrder['globalPrice'] <= $rs['priceto']) { $Data[$rulescartid][$ruleid] = 1; } else { $Data[$rulescartid][$ruleid] = 0; } } break; case 13: // final cart price with dispatch method if (isset($Data[$rulescartid][$ruleid]) && $Data[$rulescartid][$ruleid] == 0 || !isset($Data[$rulescartid][$ruleid])) { if (isset($clientOrder['priceWithDispatchMethod']) && $clientOrder['priceWithDispatchMethod'] >= $rs['pricefrom']) { $Data[$rulescartid][$ruleid] = 1; } else { $Data[$rulescartid][$ruleid] = 0; } } break; case 14: // final cart price with dispatch method if (isset($Data[$rulescartid][$ruleid]) && $Data[$rulescartid][$ruleid] == 0 || !isset($Data[$rulescartid][$ruleid])) { if ($clientOrder['priceWithDispatchMethod'] <= $rs['priceto']) { $Data[$rulescartid][$ruleid] = 1; } else { $Data[$rulescartid][$ruleid] = 0; } } break; } $discountValue = $rs['discount']; $discountSymbol = $rs['symbol']; if ($discountSymbol !== '%' && $discountValue > 0) { $shopCurrency = Session::getActiveShopCurrencyId(); $currentCurrency = Session::getActiveCurrencyId(); if ($shopCurrency != $currentCurrency) { $rate = Session::getActiveCurrencyRate(); if (!empty($rate) && $rate > 0) { $discountValue = $rate * $discountValue; } } } $discount[$rs['rulescartid']]['rulescartid'] = $rs['rulescartid']; $discount[$rs['rulescartid']]['name'] = $ruleName; $discount[$rs['rulescartid']]['description'] = $ruleDescription; $discount[$rs['rulescartid']]['suffixtypeid'] = $rs['suffixtypeid']; $discount[$rs['rulescartid']]['discount'] = $discountValue; $discount[$rs['rulescartid']]['symbol'] = $discountSymbol; $discount[$rs['rulescartid']]['freeshipping'] = $rs['freeshipping']; } } catch (Exception $e) { throw new FrontendException(_('ERR_RULES_CART')); } } // end foreach } // end if is_array rulesAll if (count($Data) > 0) { foreach ($Data as $rulescart => $rules) { foreach ($rules as $rule) { if ($rule == 0) { unset($Data[$rulescart]); } } } } foreach ($Data as $rulescart => $rules) { return $discount[$rulescart]; } }