Example #1
0
 /**
  * Add voucher to cart
  * @param string $sTicket - voucher code
  * @access public
  * @deprecated
  * @return array
  */
 public function sAddVoucher($sTicket, $BASKET = '')
 {
     if (Enlight()->Events()->notifyUntil('Shopware_Modules_Basket_AddVoucher_Start', array('subject' => $this, 'code' => $sTicket, "basket" => $BASKET))) {
         return false;
     }
     $sTicket = stripslashes($sTicket);
     $sTicket = strtolower($sTicket);
     $sql = "\n\t\tSELECT * FROM s_emarketing_vouchers WHERE LOWER(vouchercode)=?\n\t\tAND ((valid_to>=now() AND valid_from<=now()) OR valid_to is NULL)\n\t\t";
     $ticketResult = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql, array($sTicket));
     // Check if voucher was already cashed
     if ($this->sSYSTEM->_SESSION["sUserId"] && $ticketResult["id"]) {
         $userid = $this->sSYSTEM->_SESSION["sUserId"];
         $sql = "\n\t\t\tSELECT s_order_details.id AS id FROM s_order, s_order_details\n\t\t\tWHERE s_order.userID = {$userid} AND s_order_details.orderID=s_order.id \n\t\t\tAND s_order_details.articleordernumber = '{$ticketResult["ordercode"]}'\n\t\t\tAND s_order_details.ordernumber!='0'\n\t\t\t";
         $queryVoucher = $this->sSYSTEM->sDB_CONNECTION->GetAll($sql);
         if (count($queryVoucher) >= $ticketResult["numorder"] && !$ticketResult["modus"]) {
             $sErrorMessages[] = $this->snippetObject->get('VoucherFailureAlreadyUsed', 'This voucher was used in an previous order');
             return array("sErrorFlag" => true, "sErrorMessages" => $sErrorMessages);
         }
     }
     if ($ticketResult["id"]) {
         //echo "NO INDIVIDUAL CODE $sTicket";
         // Check if ticket is available anymore
         $countTicket = $this->sSYSTEM->sDB_CONNECTION->GetRow("\n\t\t\tSELECT COUNT(id) AS vouchers FROM s_order_details WHERE articleordernumber='{$ticketResult["ordercode"]}'\n\t\t\tAND s_order_details.ordernumber!='0'\n\t\t\t");
     } else {
         // Check for individual voucher - code
         $sql = "\n\t\t\tSELECT s_emarketing_voucher_codes.id AS id, s_emarketing_voucher_codes.code AS vouchercode,description, numberofunits,customergroup, value,restrictarticles, minimumcharge, shippingfree, bindtosupplier,\n\t\t\ttaxconfig,\n\t\t\tvalid_from,valid_to,ordercode, modus,percental,strict,subshopID FROM s_emarketing_vouchers, s_emarketing_voucher_codes\n\t\t\tWHERE\n\t\t\t\tmodus = 1\n\t\t\tAND\n\t\t\t\ts_emarketing_vouchers.id = s_emarketing_voucher_codes.voucherID\n\t\t\tAND\n\t\t\t\tLOWER(code) = ?\n\t\t\tAND \n\t\t\t\tcashed != 1\n\t\t\tAND ((s_emarketing_vouchers.valid_to>=now() AND s_emarketing_vouchers.valid_from<=now()) OR s_emarketing_vouchers.valid_to is NULL)\n\t\t\t";
         $ticketResult = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql, array($sTicket));
         if ($ticketResult["description"]) {
             $indivualCode = true;
         } else {
             $indivualCode = false;
         }
     }
     // Check if ticket exists
     if (!count($ticketResult) || !$sTicket || $ticketResult["numberofunits"] <= $countTicket["vouchers"] && !$indivualCode) {
         $sErrorMessages[] = $this->snippetObject->get('VoucherFailureNotFound', 'Voucher could not be found or is not valid anymore');
         return array("sErrorFlag" => true, "sErrorMessages" => $sErrorMessages);
     }
     if (!empty($ticketResult["strict"])) {
         $restrictDiscount = true;
     } else {
         $restrictDiscount = false;
     }
     if (!empty($ticketResult["subshopID"])) {
         if ($this->sSYSTEM->sSubShop["id"] != $ticketResult["subshopID"]) {
             $sErrorMessages[] = $this->snippetObject->get('VoucherFailureNotFound', 'Voucher could not be found or is not valid anymore');
             return array("sErrorFlag" => true, "sErrorMessages" => $sErrorMessages);
         }
     }
     // Check if any voucher is already in basket
     $chkBasket = $this->sSYSTEM->sDB_CONNECTION->GetRow("\n\t\tSELECT id FROM s_order_basket WHERE sessionID='" . $this->sSYSTEM->sSESSION_ID . "' AND modus=2\n\t\t");
     if (count($chkBasket)) {
         $sErrorMessages[] = $this->snippetObject->get('VoucherFailureOnlyOnes', 'Only one voucher can be processed in order');
         return array("sErrorFlag" => true, "sErrorMessages" => $sErrorMessages);
     }
     // Restrict to customergroup
     if (!empty($ticketResult["customergroup"])) {
         $userid = $this->sSYSTEM->_SESSION["sUserId"];
         if (!empty($userid)) {
             // Get customergroup
             $queryCustomergroup = $this->sSYSTEM->sDB_CONNECTION->GetRow("\n                SELECT s_core_customergroups.id, customergroup FROM s_user, s_core_customergroups WHERE s_user.id={$userid}\n                AND s_user.customergroup = s_core_customergroups.groupkey\n                ");
         }
         $customergroup = $queryCustomergroup["customergroup"];
         if ($customergroup != $ticketResult["customergroup"] && $ticketResult["customergroup"] != $queryCustomergroup["id"] && $ticketResult["customergroup"] != $this->sSYSTEM->sUSERGROUPDATA["id"]) {
             $sErrorMessages[] = $this->snippetObject->get('VoucherFailureCustomerGroup', 'This voucher is not available for your customergroup');
             return array("sErrorFlag" => true, "sErrorMessages" => $sErrorMessages);
         }
     }
     // Restrict to articles
     if (!empty($ticketResult["restrictarticles"]) && strlen($ticketResult["restrictarticles"]) > 5) {
         $restrictedArticles = explode(";", $ticketResult["restrictarticles"]);
         if (count($restrictedArticles) == 0) {
             $restrictedArticles[] = $ticketResult["restrictarticles"];
         }
         foreach ($restrictedArticles as $k => $restrictedArticle) {
             $restrictedArticles[$k] = (string) $this->sSYSTEM->sDB_CONNECTION->qstr($restrictedArticle);
         }
         $sql = "\n\t\t\tSELECT id FROM s_order_basket WHERE sessionID='" . $this->sSYSTEM->sSESSION_ID . "' AND modus=0\n\t\t\tAND ordernumber IN (" . implode(",", $restrictedArticles) . ")\n\t\t\t";
         $getOrdernumbers = $this->sSYSTEM->sDB_CONNECTION->GetOne($sql);
         $foundMatchingArticle = false;
         if (!empty($getOrdernumbers)) {
             $foundMatchingArticle = true;
         }
         if (empty($foundMatchingArticle)) {
             $sErrorMessages[] = $this->snippetObject->get('VoucherFailureProducts', 'This voucher is only available in combination with certain products');
             return array("sErrorFlag" => true, "sErrorMessages" => $sErrorMessages);
         }
     }
     // Restrict to supplier
     if ($ticketResult["bindtosupplier"]) {
         $searchHersteller = $ticketResult["bindtosupplier"];
         $sql = "\n\t\t\tSELECT s_order_basket.id FROM s_order_basket, s_articles, s_articles_supplier WHERE\n\t\t\ts_order_basket.articleID=s_articles.id AND s_articles.supplierID={$searchHersteller}\n\t\t\tAND s_order_basket.sessionID='" . $this->sSYSTEM->sSESSION_ID . "'\n\t\t\t";
         $chkHersteller = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql);
         if (!count($chkHersteller)) {
             // Name des Herstellers abfragen
             $queryHersteller = $this->sSYSTEM->sDB_CONNECTION->GetRow("\n\t\t\t\tSELECT name FROM s_articles_supplier WHERE id={$searchHersteller}\n\t\t\t\t");
             $sErrorMessages[] = str_replace("{sSupplier}", $queryHersteller["name"], $this->snippetObject->get('VoucherFailureSupplier', 'This voucher is only available for products from {sSupplier}'));
             return array("sErrorFlag" => true, "sErrorMessages" => $sErrorMessages);
         }
     }
     if (!empty($restrictDiscount) && (!empty($restrictedArticles) || !empty($searchHersteller))) {
         $amount = $this->sGetAmountRestrictedArticles($restrictedArticles, $searchHersteller);
     } else {
         $amount = $this->sGetAmountArticles();
     }
     if ($this->sSYSTEM->sCurrency["factor"] && empty($ticketResult["percental"])) {
         $factor = $this->sSYSTEM->sCurrency["factor"];
         $ticketResult["value"] *= $factor;
     } else {
         $factor = 1;
     }
     if ($amount["totalAmount"] / $factor < $ticketResult["minimumcharge"]) {
         $sErrorMessages[] = str_replace("{sMinimumCharge}", $ticketResult["minimumcharge"], $this->snippetObject->get('VoucherFailureMinimumCharge', 'The minimum charge for this voucher is {sMinimumCharge}'));
         return array("sErrorFlag" => true, "sErrorMessages" => $sErrorMessages);
     }
     $timeInsert = date("Y-m-d H:i:s");
     $vouchername = $this->sSYSTEM->sCONFIG['sVOUCHERNAME'];
     if ($ticketResult["percental"]) {
         $value = $ticketResult["value"];
         $vouchername .= " " . $value . " %";
         $ticketResult["value"] = $amount["totalAmount"] / 100 * floatval($value);
     }
     // Free tax configuration for vouchers
     // Trac ticket 4708 st.hamann
     $taxRate = 0;
     if (!$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"] || $ticketResult["taxconfig"] == "none") {
         // if net customergroup - calculate without tax
         $tax = $ticketResult["value"] * -1;
         if ($ticketResult["taxconfig"] == "default" || empty($ticketResult["taxconfig"])) {
             $taxRate = $this->sSYSTEM->sCONFIG['sVOUCHERTAX'];
         } elseif ($ticketResult["taxconfig"] == "auto") {
             $taxRate = $this->getMaxTax();
         } elseif (intval($ticketResult["taxconfig"])) {
             $temporaryTax = $ticketResult["taxconfig"];
             $getTaxRate = $this->sSYSTEM->sDB_CONNECTION->getOne("\n               SELECT tax FROM s_core_tax WHERE id = ?\n               ", array($temporaryTax));
             $taxRate = $getTaxRate;
         }
     } else {
         if ($ticketResult["taxconfig"] == "default" || empty($ticketResult["taxconfig"])) {
             $tax = round($ticketResult["value"] / (100 + $this->sSYSTEM->sCONFIG['sVOUCHERTAX']) * 100, 3) * -1;
             $taxRate = $this->sSYSTEM->sCONFIG['sVOUCHERTAX'];
             // Pre 3.5.4 behaviour
         } elseif ($ticketResult["taxconfig"] == "auto") {
             // Check max. used tax-rate from basket
             $tax = $this->getMaxTax();
             $taxRate = $tax;
             $tax = round($ticketResult["value"] / (100 + $tax) * 100, 3) * -1;
         } elseif (intval($ticketResult["taxconfig"])) {
             // Fix defined tax
             $temporaryTax = $ticketResult["taxconfig"];
             $getTaxRate = $this->sSYSTEM->sDB_CONNECTION->getOne("\n\t\t\t\tSELECT tax FROM s_core_tax WHERE id = ?\n\t\t\t\t", array($temporaryTax));
             $taxRate = $getTaxRate;
             $tax = round($ticketResult["value"] / (100 + $getTaxRate) * 100, 3) * -1;
         } else {
             // No tax
             $tax = $ticketResult["value"] * -1;
         }
     }
     $ticketResult["value"] = $ticketResult["value"] * -1;
     if ($ticketResult["shippingfree"]) {
         $shippingfree = "1";
     } else {
         $shippingfree = "0";
     }
     $sql = "\n\t\tINSERT INTO s_order_basket (sessionID, articlename, articleID, ordernumber, shippingfree, quantity, price, netprice,tax_rate, datum, modus, currencyFactor)\n\t\tVALUES (?,?,?,?,?,1,?,?,?,?,2,?)\n\t\t";
     $params = array($this->sSYSTEM->sSESSION_ID, $vouchername, $ticketResult["id"], $ticketResult["ordercode"], $shippingfree, $ticketResult["value"], $tax, $taxRate, $timeInsert, $this->sSYSTEM->sCurrency["factor"]);
     $sql = Enlight()->Events()->filter('Shopware_Modules_Basket_AddVoucher_FilterSql', $sql, array('subject' => $this, "params" => $params, "voucher" => $ticketResult, "name" => $vouchername, "shippingfree" => $shippingfree, "tax" => $tax));
     if (!$this->sSYSTEM->sDB_CONNECTION->Execute($sql, $params)) {
         return false;
     }
     return true;
 }
Example #2
0
    /**
     * Subscribe / unsubscribe to mailing list
     * @param string $email - mail
     * @param boolean $unsubscribe
     * @param id $groupID id of the mailinglist group
     * @access public
     * @return boolean
     */
    public function sNewsletterSubscription($email, $unsubscribe = false, $groupID = null)
    {
        if (empty($unsubscribe)) {
            $errorflag = array();
            /**
             * Only the mail address needs to be a mandatory item
             * @ticket #5781
             * @author S.Pohl <*****@*****.**>
             * @date 2011-07-27
             */
            $fields = array('newsletter');
            foreach ($fields as $field) {
                if (isset($this->sSYSTEM->_POST[$field]) && empty($this->sSYSTEM->_POST[$field])) {
                    $errorflag[$field] = true;
                }
            }
            if (!empty($errorflag)) {
                return array('code' => 5, 'message' => $this->snippetObject->get('ErrorFillIn', 'Please fill in all red fields'), 'sErrorFlag' => $errorflag);
            }
        }
        if (empty($groupID)) {
            $groupID = $this->sSYSTEM->sCONFIG["sNEWSLETTERDEFAULTGROUP"];
            $sql = '
				INSERT IGNORE INTO s_campaigns_groups (id, name)
				VALUES (?, ?)
			';
            $this->sSYSTEM->sDB_CONNECTION->Execute($sql, array($groupID, 'Newsletter-Empfänger'));
        }
        $email = trim(strtolower(stripslashes($email)));
        if (empty($email)) {
            return array("code" => 6, "message" => $this->snippetObject->get('NewsletterFailureMail', 'Enter eMail address'));
        }
        $reg = "/^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\"([^\"\\\\\r]|(\\\\[\\w\\W]))*\"))@((\\[([0-9]{1,3}\\.){3}[0-9]{1,3}\\])|(([a-z\\-0-9áàäçéèêñóòôöüæøå]+\\.)+[a-z]{2,}))\$/i";
        if (!preg_match($reg, $email)) {
            return array("code" => 1, "message" => $this->snippetObject->get('NewsletterFailureInvalid', 'Enter valid eMail address'));
        }
        if (!$unsubscribe) {
            $sql = "SELECT * FROM s_campaigns_mailaddresses WHERE email=?";
            $result = $this->sSYSTEM->sDB_CONNECTION->Execute($sql, array($email));
            if ($result === false) {
                $result = array("code" => 10, "message" => $this->snippetObject->get('UnknownError', 'Unknown error'));
            } elseif ($result->RecordCount()) {
                $result = array("code" => 2, "message" => $this->snippetObject->get('NewsletterFailureAlreadyRegistered', 'You already receive our newsletter'));
            } else {
                $sql = "INSERT INTO s_campaigns_mailaddresses (`groupID`,email) VALUES(?, ?)";
                $result = $this->sSYSTEM->sDB_CONNECTION->Execute($sql, array($groupID, $email));
                if ($result === false) {
                    $result = array("code" => 10, "message" => $this->snippetObject->get('UnknownError', 'Unknown error'));
                } else {
                    $result = array("code" => 3, "message" => $this->snippetObject->get('NewsletterSuccess', 'Thank you for receiving our newsletter'));
                }
            }
        } else {
            $sql = "DELETE FROM s_campaigns_mailaddresses WHERE email=?";
            $result1 = $this->sSYSTEM->sDB_CONNECTION->Execute($sql, array($email));
            $result = $this->sSYSTEM->sDB_CONNECTION->Affected_Rows();
            $sql = "UPDATE s_user SET newsletter=0 WHERE email=?";
            $result2 = $this->sSYSTEM->sDB_CONNECTION->Execute($sql, array($email));
            $result += $this->sSYSTEM->sDB_CONNECTION->Affected_Rows();
            if ($result1 === false || $result2 === false) {
                $result = array("code" => 10, "message" => $this->snippetObject->get('UnknownError', 'Unknown error'));
            } elseif (empty($result)) {
                $result = array("code" => 4, "message" => $this->snippetObject->get('NewsletterFailureNotFound', 'This mail address could not be found'));
            } else {
                $result = array("code" => 5, "message" => $this->snippetObject->get('NewsletterMailDeleted', 'Your mail address was deleted'));
            }
        }
        if (!empty($result['code']) && in_array($result['code'], array(2, 3))) {
            $sql = '
				REPLACE INTO `s_campaigns_maildata` (`email`, `groupID`, `salutation`, `title`, `firstname`, `lastname`, `street`, `streetnumber`, `zipcode`, `city`, `added`)
				VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ' . $this->sSYSTEM->sDB_CONNECTION->sysTimeStamp . ')
			';
            $this->sSYSTEM->sDB_CONNECTION->Execute($sql, array($email, $groupID, $this->sSYSTEM->_POST['salutation'], $this->sSYSTEM->_POST['title'], $this->sSYSTEM->_POST['firstname'], $this->sSYSTEM->_POST['lastname'], $this->sSYSTEM->_POST['street'], $this->sSYSTEM->_POST['streetnumber'], $this->sSYSTEM->_POST['zipcode'], $this->sSYSTEM->_POST['city']));
        } elseif (!empty($unsubscribe)) {
            $sql = 'DELETE FROM `s_campaigns_maildata` WHERE `email`=? AND `groupID`=?';
            $this->sSYSTEM->sDB_CONNECTION->Execute($sql, array($email, $groupID));
        }
        return $result;
    }