Esempio n. 1
0
 private function createProperties($groupCount, $optionCount, $namePrefix = 'Test')
 {
     $this->propertyNames[] = $namePrefix;
     $this->deleteProperties($namePrefix);
     $this->db->insert('s_filter', array('name' => $namePrefix . '-Set', 'comparable' => 1));
     $data = $this->db->fetchRow("SELECT * FROM s_filter WHERE name = '" . $namePrefix . "-Set'");
     for ($i = 0; $i < $groupCount; $i++) {
         $this->db->insert('s_filter_options', array('name' => $namePrefix . '-Gruppe-' . $i, 'filterable' => 1));
         $group = $this->db->fetchRow("SELECT * FROM s_filter_options WHERE name = '" . $namePrefix . "-Gruppe-" . $i . "'");
         for ($i2 = 0; $i2 < $optionCount; $i2++) {
             $this->db->insert('s_filter_values', array('value' => $namePrefix . '-Option-' . $i . '-' . $i2, 'optionID' => $group['id']));
         }
         $group['options'] = $this->db->fetchAll("SELECT * FROM s_filter_values WHERE optionID = ?", array($group['id']));
         $data['groups'][] = $group;
         $this->db->insert('s_filter_relations', array('optionID' => $group['id'], 'groupID' => $data['id']));
     }
     return $data;
 }
Esempio n. 2
0
 /**
  * Helper method for sAdmin::sGetPremiumShippingcosts()
  * Calculates payment mean surcharge
  *
  * @param $country
  * @param $payment
  * @param $currencyFactor
  * @param $dispatch
  * @param $discount_tax
  */
 private function handlePaymentMeanSurcharge($country, $payment, $currencyFactor, $dispatch, $discount_tax)
 {
     $surcharge_name = $this->snippetManager->getNamespace('backend/static/discounts_surcharges')->get('payment_surcharge_absolute', 'Surcharge for payment');
     $surcharge_ordernumber = $this->config->get('sPAYMENTSURCHARGEABSOLUTENUMBER', 'PAYMENTSURCHARGEABSOLUTENUMBER');
     $percent_ordernumber = $this->config->get('sPAYMENTSURCHARGENUMBER', "PAYMENTSURCHARGE");
     // Country surcharge
     if (!empty($payment['country_surcharge'][$country['countryiso']])) {
         $payment['surcharge'] += $payment['country_surcharge'][$country['countryiso']];
     }
     $payment['surcharge'] = round($payment['surcharge'] * $currencyFactor, 2);
     // Fixed surcharge
     if (!empty($payment['surcharge']) && (empty($dispatch) || $dispatch['surcharge_calculation'] == 3)) {
         $surcharge = round($payment['surcharge'], 2);
         $payment['surcharge'] = 0;
         if (empty($this->sSYSTEM->sUSERGROUPDATA["tax"]) && !empty($this->sSYSTEM->sUSERGROUPDATA["id"])) {
             $surcharge_net = $surcharge;
             //$tax_rate = 0;
         } else {
             $surcharge_net = round($surcharge / (100 + $discount_tax) * 100, 2);
         }
         $tax_rate = $discount_tax;
         $this->db->insert('s_order_basket', array('sessionID' => $this->session->offsetGet('sessionId'), 'articlename' => $surcharge_name, 'articleID' => 0, 'ordernumber' => $surcharge_ordernumber, 'quantity' => 1, 'price' => $surcharge, 'netprice' => $surcharge_net, 'tax_rate' => $tax_rate, 'datum' => new Zend_Date(), 'modus' => 4, 'currencyFactor' => $currencyFactor));
     }
     // Percentage surcharge
     if (!empty($payment['debit_percent']) && (empty($dispatch) || $dispatch['surcharge_calculation'] != 2)) {
         $amount = $this->db->fetchOne('SELECT SUM(quantity*price) as amount
             FROM s_order_basket
             WHERE sessionID = ? GROUP BY sessionID', array($this->session->offsetGet('sessionId')));
         $percent = round($amount / 100 * $payment['debit_percent'], 2);
         if ($percent > 0) {
             $percent_name = $this->snippetManager->getNamespace('backend/static/discounts_surcharges')->get('payment_surcharge_add');
         } else {
             $percent_name = $this->snippetManager->getNamespace('backend/static/discounts_surcharges')->get('payment_surcharge_dev');
         }
         if (empty($this->sSYSTEM->sUSERGROUPDATA["tax"]) && !empty($this->sSYSTEM->sUSERGROUPDATA["id"])) {
             $percent_net = $percent;
         } else {
             $percent_net = round($percent / (100 + $discount_tax) * 100, 2);
         }
         $tax_rate = $discount_tax;
         $this->db->insert('s_order_basket', array('sessionID' => $this->session->offsetGet('sessionId'), 'articlename' => $percent_name, 'articleID' => 0, 'ordernumber' => $percent_ordernumber, 'quantity' => 1, 'price' => $percent, 'netprice' => $percent_net, 'tax_rate' => $tax_rate, 'datum' => new Zend_Date(), 'modus' => 4, 'currencyFactor' => $currencyFactor));
     }
     return $payment;
 }
Esempio n. 3
0
 /**
  * @param array $category
  * @return bool|int
  */
 public function import(array $category)
 {
     $category = $this->prepareCategoryData($category);
     // Try to find an existing category by name and parent
     $model = null;
     if (isset($category['parent']) && isset($category['name'])) {
         $model = $this->repository->findOneBy(['parent' => $category['parent'], 'name' => $category['name']]);
     }
     if (!$model instanceof Category) {
         $model = new Category();
     }
     $parentModel = null;
     if (isset($category['parent'])) {
         $parentModel = $this->repository->find((int) $category['parent']);
         if (!$parentModel instanceof Category) {
             $this->logger->error("Parent category {$category['parent']} not found!");
             return false;
         }
     }
     $model->fromArray($category);
     $model->setParent($parentModel);
     $this->em->persist($model);
     $this->em->flush();
     // Set category attributes
     $attributes = $this->prepareCategoryAttributesData($category);
     unset($category);
     $categoryId = $model->getId();
     if (!empty($attributes)) {
         $attributeID = $this->db->fetchOne("SELECT id FROM s_categories_attributes WHERE categoryID = ?", [$categoryId]);
         if ($attributeID === false) {
             $attributes['categoryID'] = $categoryId;
             $this->db->insert('s_categories_attributes', $attributes);
         } else {
             $this->db->update('s_categories_attributes', $attributes, ['categoryID = ?' => $categoryId]);
         }
     }
     return $categoryId;
 }
Esempio n. 4
0
 /**
  * Add product to cart
  * Used in multiple locations
  *
  * @param int $id Order number (s_articles_details.ordernumber)
  * @param int $quantity Amount
  * @throws Enlight_Exception If no price could be determined, or a database error occurs
  * @return int|false Id of the inserted basket entry, or false on failure
  */
 public function sAddArticle($id, $quantity = 1)
 {
     $sessionId = $this->session->get('sessionId');
     if ($this->session->get('Bot') || empty($sessionId)) {
         return false;
     }
     $quantity = empty($quantity) || !is_numeric($quantity) ? 1 : (int) $quantity;
     if ($quantity <= 0) {
         $quantity = 1;
     }
     if ($this->eventManager->notifyUntil('Shopware_Modules_Basket_AddArticle_Start', array('subject' => $this, 'id' => $id, "quantity" => $quantity))) {
         return false;
     }
     $article = $this->getArticleForAddArticle($id);
     if (!$article) {
         return false;
     }
     $chkBasketForArticle = $this->checkIfArticleIsInBasket($article["articleID"], $article["ordernumber"], $sessionId);
     // Shopware 3.5.0 / sth / laststock - instock check
     if (!empty($chkBasketForArticle["id"])) {
         if ($article["laststock"] == true && $article["instock"] < $chkBasketForArticle["quantity"] + $quantity) {
             $quantity -= $chkBasketForArticle["quantity"];
         }
     } else {
         if ($article["laststock"] == true && $article["instock"] <= $quantity) {
             $quantity = $article["instock"];
             if ($quantity <= 0) {
                 return;
             }
         }
     }
     if ($chkBasketForArticle) {
         // Article is already in basket, update quantity
         $quantity += $chkBasketForArticle["quantity"];
         $this->sUpdateArticle($chkBasketForArticle["id"], $quantity);
         return $chkBasketForArticle["id"];
     }
     $price = $this->getPriceForAddArticle($article);
     // For variants, extend the article name
     if ($article["additionaltext"]) {
         $article["articleName"] .= " " . $article["additionaltext"];
     }
     if (!$article["shippingfree"]) {
         $article["shippingfree"] = "0";
     }
     // Check if article is an esd-article
     // - add flag to basket
     $getEsd = $this->db->fetchOne('SELECT s_articles_esd.id AS id, serials
         FROM s_articles_esd, s_articles_details
         WHERE s_articles_esd.articleID = ?
         AND s_articles_esd.articledetailsID = s_articles_details.id
         AND s_articles_details.ordernumber = ?', array($article["articleID"], $article["ordernumber"]));
     $sEsd = $getEsd ? '1' : '0';
     $quantity = (int) $quantity;
     $sql = "\n            INSERT INTO s_order_basket (id, sessionID, userID, articlename, articleID,\n                ordernumber, shippingfree, quantity, price, netprice,\n                datum, esdarticle, partnerID, config)\n            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )\n        ";
     $params = array('', (string) $sessionId, (string) $this->session->get('sUserId'), $article["articleName"], $article["articleID"], (string) $article["ordernumber"], $article["shippingfree"], $quantity, $price["price"], $price["netprice"], date("Y-m-d H:i:s"), $sEsd, (string) $this->session->get('sPartner'), '');
     $sql = $this->eventManager->filter('Shopware_Modules_Basket_AddArticle_FilterSql', $sql, array('subject' => $this, 'article' => $article, 'price' => $price, 'esd' => $sEsd, 'quantity' => $quantity, 'partner' => $this->session->get('sPartner')));
     $result = $this->db->query($sql, $params);
     if (!$result) {
         throw new Enlight_Exception("BASKET-INSERT #02 SQL-Error" . $sql);
     }
     $insertId = $this->db->lastInsertId();
     $this->db->insert('s_order_basket_attributes', array('basketID' => $insertId, 'attribute1' => ''));
     $this->sUpdateArticle($insertId, $quantity);
     return $insertId;
 }
Esempio n. 5
0
 /**
  * Finaly save order and send order confirmation to customer
  * @access public
  */
 public function sSaveOrder()
 {
     $this->sComment = stripslashes($this->sComment);
     $this->sComment = stripcslashes($this->sComment);
     $this->sShippingData["AmountNumeric"] = $this->sShippingData["AmountNumeric"] ? $this->sShippingData["AmountNumeric"] : "0";
     if ($this->isTransactionExist($this->bookingId)) {
         return false;
     }
     // Insert basic-data of the order
     $orderNumber = $this->sGetOrderNumber();
     $this->sOrderNumber = $orderNumber;
     if (!$this->sShippingcostsNumeric) {
         $this->sShippingcostsNumeric = "0";
     }
     if (!$this->sBasketData["AmountWithTaxNumeric"]) {
         $this->sBasketData["AmountWithTaxNumeric"] = $this->sBasketData["AmountNumeric"];
     }
     if ($this->isTaxFree($this->sSYSTEM->sUSERGROUPDATA["tax"], $this->sSYSTEM->sUSERGROUPDATA["id"])) {
         $net = "1";
     } else {
         $net = "0";
     }
     if ($this->dispatchId) {
         $dispatchId = $this->dispatchId;
     } else {
         $dispatchId = "0";
     }
     $this->sBasketData["AmountNetNumeric"] = round($this->sBasketData["AmountNetNumeric"], 2);
     if (empty($this->sSYSTEM->sCurrency["currency"])) {
         $this->sSYSTEM->sCurrency["currency"] = "EUR";
     }
     if (empty($this->sSYSTEM->sCurrency["factor"])) {
         $this->sSYSTEM->sCurrency["factor"] = "1";
     }
     $shop = Shopware()->Shop();
     $mainShop = $shop->getMain() !== null ? $shop->getMain() : $shop;
     $taxfree = "0";
     if (!empty($this->sNet)) {
         // Complete net delivery
         $net = "1";
         $this->sBasketData["AmountWithTaxNumeric"] = $this->sBasketData["AmountNetNumeric"];
         $this->sShippingcostsNumeric = $this->sShippingcostsNumericNet;
         $taxfree = "1";
     }
     $partner = $this->getPartnerCode($this->sUserData["additional"]["user"]["affiliate"]);
     $orderParams = array('ordernumber' => $orderNumber, 'userID' => $this->sUserData["additional"]["user"]["id"], 'invoice_amount' => $this->sBasketData["AmountWithTaxNumeric"], 'invoice_amount_net' => $this->sBasketData["AmountNetNumeric"], 'invoice_shipping' => floatval($this->sShippingcostsNumeric), 'invoice_shipping_net' => floatval($this->sShippingcostsNumericNet), 'ordertime' => new Zend_Db_Expr('NOW()'), 'status' => 0, 'cleared' => 17, 'paymentID' => $this->sUserData["additional"]["user"]["paymentID"], 'transactionID' => (string) $this->bookingId, 'customercomment' => $this->sComment, 'net' => $net, 'taxfree' => $taxfree, 'partnerID' => (string) $partner, 'temporaryID' => (string) $this->uniqueID, 'referer' => (string) $this->getSession()->offsetGet('sReferer'), 'language' => $shop->getId(), 'dispatchID' => $dispatchId, 'currency' => $this->sSYSTEM->sCurrency["currency"], 'currencyFactor' => $this->sSYSTEM->sCurrency["factor"], 'subshopID' => $mainShop->getId(), 'remote_addr' => (string) $_SERVER['REMOTE_ADDR'], 'deviceType' => $this->deviceType);
     $orderParams = $this->eventManager->filter('Shopware_Modules_Order_SaveOrder_FilterParams', $orderParams, array('subject' => $this));
     try {
         $this->db->beginTransaction();
         $affectedRows = $this->db->insert('s_order', $orderParams);
         $orderID = $this->db->lastInsertId();
         $this->db->commit();
     } catch (Exception $e) {
         $this->db->rollBack();
         throw new Enlight_Exception("Shopware Order Fatal-Error {$_SERVER["HTTP_HOST"]} :" . $e->getMessage(), 0, $e);
     }
     if (!$affectedRows || !$orderID) {
         throw new Enlight_Exception("Shopware Order Fatal-Error {$_SERVER["HTTP_HOST"]} : No rows affected or no order id created.", 0);
     }
     try {
         $paymentData = Shopware()->Modules()->Admin()->sGetPaymentMeanById($this->sUserData["additional"]["user"]["paymentID"], Shopware()->Modules()->Admin()->sGetUserData());
         $paymentClass = Shopware()->Modules()->Admin()->sInitiatePaymentClass($paymentData);
         if ($paymentClass instanceof \ShopwarePlugin\PaymentMethods\Components\BasePaymentMethod) {
             $paymentClass->createPaymentInstance($orderID, $this->sUserData["additional"]["user"]["id"], $this->sUserData["additional"]["user"]["paymentID"]);
         }
     } catch (\Exception $e) {
         //Payment method code failure
     }
     $attributeSql = "INSERT INTO s_order_attributes (orderID, attribute1, attribute2, attribute3, attribute4, attribute5, attribute6)\n                VALUES (\n                    " . $orderID . ",\n                    " . $this->db->quote((string) $this->o_attr_1) . ",\n                    " . $this->db->quote((string) $this->o_attr_2) . ",\n                    " . $this->db->quote((string) $this->o_attr_3) . ",\n                    " . $this->db->quote((string) $this->o_attr_4) . ",\n                    " . $this->db->quote((string) $this->o_attr_5) . ",\n                    " . $this->db->quote((string) $this->o_attr_6) . "\n                )";
     $attributeSql = $this->eventManager->filter('Shopware_Modules_Order_SaveOrderAttributes_FilterSQL', $attributeSql, array('subject' => $this));
     $this->db->executeUpdate($attributeSql);
     $attributes = $this->getOrderAttributes($orderID);
     unset($attributes['id']);
     unset($attributes['orderID']);
     $position = 0;
     foreach ($this->sBasketData["content"] as $key => $basketRow) {
         $position++;
         $basketRow = $this->formatBasketRow($basketRow);
         $preparedQuery = "\n            INSERT INTO s_order_details\n                (orderID,\n                ordernumber,\n                articleID,\n                articleordernumber,\n                price,\n                quantity,\n                name,\n                status,\n                releasedate,\n                modus,\n                esdarticle,\n                taxID,\n                tax_rate,\n                ean,\n                unit,\n                pack_unit\n                )\n                VALUES (%d, %s, %d, %s, %f, %d, %s, %d, %s, %d, %d, %d, %f, %s, %s, %s)\n            ";
         $sql = sprintf($preparedQuery, $orderID, $this->db->quote((string) $orderNumber), $basketRow["articleID"], $this->db->quote((string) $basketRow["ordernumber"]), $basketRow["priceNumeric"], $basketRow["quantity"], $this->db->quote((string) $basketRow["articlename"]), 0, $this->db->quote((string) $basketRow["releasedate"]), $basketRow["modus"], $basketRow["esdarticle"], $basketRow["taxID"], $basketRow["tax_rate"], $this->db->quote((string) $basketRow["ean"]), $this->db->quote((string) $basketRow["itemUnit"]), $this->db->quote((string) $basketRow["packunit"]));
         $sql = $this->eventManager->filter('Shopware_Modules_Order_SaveOrder_FilterDetailsSQL', $sql, array('subject' => $this, 'row' => $basketRow, 'user' => $this->sUserData, 'order' => array("id" => $orderID, "number" => $orderNumber)));
         // Check for individual voucher - code
         if ($basketRow["modus"] == 2) {
             //reserve the basket voucher for the current user.
             $this->reserveVoucher($basketRow["ordernumber"], $this->sUserData["additional"]["user"]["id"], $basketRow["articleID"]);
         }
         if ($basketRow["esdarticle"]) {
             $esdOrder = true;
         }
         try {
             $this->db->executeUpdate($sql);
             $orderdetailsID = $this->db->lastInsertId();
         } catch (Exception $e) {
             throw new Enlight_Exception("Shopware Order Fatal-Error {$_SERVER["HTTP_HOST"]} :" . $e->getMessage(), 0, $e);
         }
         $this->sBasketData['content'][$key]['orderDetailId'] = $orderdetailsID;
         //new attribute tables
         $attributeSql = "INSERT INTO s_order_details_attributes (detailID, attribute1, attribute2, attribute3, attribute4, attribute5, attribute6)\n                             VALUES (" . $orderdetailsID . "," . $this->db->quote((string) $basketRow["ob_attr1"]) . "," . $this->db->quote((string) $basketRow["ob_attr2"]) . "," . $this->db->quote((string) $basketRow["ob_attr3"]) . "," . $this->db->quote((string) $basketRow["ob_attr4"]) . "," . $this->db->quote((string) $basketRow["ob_attr5"]) . "," . $this->db->quote((string) $basketRow["ob_attr6"]) . ")";
         $attributeSql = $this->eventManager->filter('Shopware_Modules_Order_SaveOrderAttributes_FilterDetailsSQL', $attributeSql, array('subject' => $this, 'row' => $basketRow, 'user' => $this->sUserData, 'order' => array("id" => $orderID, "number" => $orderNumber)));
         $this->db->executeUpdate($attributeSql);
         $detailAttributes = $this->getOrderDetailAttributes($orderdetailsID);
         unset($detailAttributes['id']);
         unset($detailAttributes['detailID']);
         $this->sBasketData['content'][$key]['attributes'] = $detailAttributes;
         // Update sales and stock
         if ($basketRow["priceNumeric"] >= 0) {
             $this->refreshOrderedVariant($basketRow["ordernumber"], $basketRow["quantity"]);
         }
         // For esd-articles, assign serial number if needed
         // Check if this article is esd-only (check in variants, too -> later)
         if ($basketRow["esdarticle"]) {
             $basketRow = $this->handleESDOrder($basketRow, $orderID, $orderdetailsID);
             // Add assignedSerials to basketcontent
             if (!empty($basketRow['assignedSerials'])) {
                 $this->sBasketData["content"][$key]['serials'] = $basketRow['assignedSerials'];
             }
         }
     }
     // For every article in basket
     $this->eventManager->notify('Shopware_Modules_Order_SaveOrder_ProcessDetails', array('subject' => $this, 'details' => $this->sBasketData['content']));
     $this->sUserData = $this->getUserDataForMail($this->sUserData);
     $details = $this->getOrderDetailsForMail($this->sBasketData["content"]);
     $variables = array("sOrderDetails" => $details, "billingaddress" => $this->sUserData["billingaddress"], "shippingaddress" => $this->sUserData["shippingaddress"], "additional" => $this->sUserData["additional"], "sShippingCosts" => $this->sSYSTEM->sMODULES['sArticles']->sFormatPrice($this->sShippingcosts) . " " . $this->sSYSTEM->sCurrency["currency"], "sAmount" => $this->sAmountWithTax ? $this->sSYSTEM->sMODULES['sArticles']->sFormatPrice($this->sAmountWithTax) . " " . $this->sSYSTEM->sCurrency["currency"] : $this->sSYSTEM->sMODULES['sArticles']->sFormatPrice($this->sAmount) . " " . $this->sSYSTEM->sCurrency["currency"], "sAmountNet" => $this->sSYSTEM->sMODULES['sArticles']->sFormatPrice($this->sBasketData["AmountNetNumeric"]) . " " . $this->sSYSTEM->sCurrency["currency"], "sTaxRates" => $this->sBasketData["sTaxRates"], "ordernumber" => $orderNumber, "sOrderDay" => date("d.m.Y"), "sOrderTime" => date("H:i"), "sComment" => $this->sComment, 'attributes' => $attributes, "sEsd" => $esdOrder);
     if ($dispatchId) {
         $variables["sDispatch"] = $this->sSYSTEM->sMODULES['sAdmin']->sGetPremiumDispatch($dispatchId);
     }
     if ($this->bookingId) {
         $variables['sBookingID'] = $this->bookingId;
     }
     // Save Billing and Shipping-Address to retrace in future
     $this->sSaveBillingAddress($this->sUserData["billingaddress"], $orderID);
     $this->sSaveShippingAddress($this->sUserData["shippingaddress"], $orderID);
     // Completed - Garbage basket / temporary - order
     $this->sDeleteTemporaryOrder();
     $this->db->executeUpdate("DELETE FROM s_order_basket WHERE sessionID=?", array($this->getSession()->offsetGet('sessionId')));
     $confirmMailDeliveryFailed = false;
     try {
         $this->sendMail($variables);
     } catch (\Exception $e) {
         $confirmMailDeliveryFailed = true;
         $email = $this->sUserData['additional']['user']['email'];
         $this->logOrderMailException($e, $orderNumber, $email);
     }
     // Check if voucher is affected
     $this->sTellFriend();
     if ($this->getSession()->offsetExists('sOrderVariables')) {
         $variables = $this->getSession()->offsetGet('sOrderVariables');
         $variables['sOrderNumber'] = $orderNumber;
         $variables['confirmMailDeliveryFailed'] = $confirmMailDeliveryFailed;
         $this->getSession()->offsetSet('sOrderVariables', $variables);
     }
     return $orderNumber;
 }
Esempio n. 6
0
 /**
  * Create temporary order (for order cancelation reports)
  * @access public
  */
 public function sCreateTemporaryOrder()
 {
     $this->sShippingData["AmountNumeric"] = $this->sShippingData["AmountNumeric"] ? $this->sShippingData["AmountNumeric"] : "0";
     if (!$this->sShippingcostsNumeric) {
         $this->sShippingcostsNumeric = "0";
     }
     if (!$this->sBasketData["AmountWithTaxNumeric"]) {
         $this->sBasketData["AmountWithTaxNumeric"] = $this->sBasketData["AmountNumeric"];
     }
     if ($this->isTaxFree($this->sSYSTEM->sUSERGROUPDATA["tax"], $this->sSYSTEM->sUSERGROUPDATA["id"])) {
         $net = "1";
     } else {
         $net = "0";
     }
     $this->sBasketData["AmountNetNumeric"] = round($this->sBasketData["AmountNetNumeric"], 2);
     if ($this->dispatchId) {
         $dispatchId = $this->dispatchId;
     } else {
         $dispatchId = "0";
     }
     $this->sBasketData["AmountNetNumeric"] = round($this->sBasketData["AmountNetNumeric"], 2);
     if (empty($this->sSYSTEM->sCurrency["currency"])) {
         $this->sSYSTEM->sCurrency["currency"] = "EUR";
     }
     if (empty($this->sSYSTEM->sCurrency["factor"])) {
         $this->sSYSTEM->sCurrency["factor"] = "1";
     }
     $shop = Shopware()->Shop();
     $mainShop = $shop->getMain() !== null ? $shop->getMain() : $shop;
     $taxfree = "0";
     if (!empty($this->sNet)) {
         // Complete net delivery
         $net = "1";
         $this->sBasketData["AmountWithTaxNumeric"] = $this->sBasketData["AmountNetNumeric"];
         $this->sShippingcostsNumeric = $this->sShippingcostsNumericNet;
         $taxfree = "1";
     }
     if (empty($this->sBasketData["AmountWithTaxNumeric"])) {
         $this->sBasketData["AmountWithTaxNumeric"] = '0';
     }
     if (empty($this->sBasketData["AmountNetNumeric"])) {
         $this->sBasketData["AmountNetNumeric"] = '0';
     }
     $data = array('ordernumber' => '0', 'userID' => $this->sUserData["additional"]["user"]["id"], 'invoice_amount' => $this->sBasketData["AmountWithTaxNumeric"], 'invoice_amount_net' => $this->sBasketData["AmountNetNumeric"], 'invoice_shipping' => $this->sShippingcostsNumeric, 'invoice_shipping_net' => $this->sShippingcostsNumericNet, 'ordertime' => new Zend_Db_Expr('NOW()'), 'status' => -1, 'paymentID' => $this->sUserData["additional"]["user"]["paymentID"], 'customercomment' => $this->sComment, 'net' => $net, 'taxfree' => $taxfree, 'partnerID' => (string) $this->getSession()->offsetGet("sPartner"), 'temporaryID' => $this->getSession()->offsetGet('sessionId'), 'referer' => (string) $this->getSession()->offsetGet('sReferer'), 'language' => $shop->getId(), 'dispatchID' => $dispatchId, 'currency' => $this->sSYSTEM->sCurrency["currency"], 'currencyFactor' => $this->sSYSTEM->sCurrency["factor"], 'subshopID' => $mainShop->getId());
     try {
         $affectedRows = $this->db->insert('s_order', $data);
         $orderID = $this->db->lastInsertId();
     } catch (Exception $e) {
         throw new Enlight_Exception("##sOrder-sTemporaryOrder-#01:" . $e->getMessage(), 0, $e);
     }
     if (!$affectedRows || !$orderID) {
         throw new Enlight_Exception("##sOrder-sTemporaryOrder-#01: No rows affected or no order id saved", 0);
     }
     $position = 0;
     foreach ($this->sBasketData["content"] as $basketRow) {
         $position++;
         if (!$basketRow["price"]) {
             $basketRow["price"] = "0,00";
         }
         $basketRow["articlename"] = html_entity_decode($basketRow["articlename"]);
         $basketRow["articlename"] = strip_tags($basketRow["articlename"]);
         $basketRow["articlename"] = $this->sSYSTEM->sMODULES['sArticles']->sOptimizeText($basketRow["articlename"]);
         if (!$basketRow["esdarticle"]) {
             $basketRow["esdarticle"] = "0";
         }
         if (!$basketRow["modus"]) {
             $basketRow["modus"] = "0";
         }
         if (!$basketRow["taxID"]) {
             $basketRow["taxID"] = "0";
         }
         $data = array('orderID' => $orderID, 'ordernumber' => 0, 'articleID' => $basketRow["articleID"], 'articleordernumber' => $basketRow["ordernumber"], 'price' => $basketRow["priceNumeric"], 'quantity' => $basketRow["quantity"], 'name' => $basketRow["articlename"], 'status' => 0, 'releasedate' => '0000-00-00', 'modus' => $basketRow["modus"], 'esdarticle' => $basketRow["esdarticle"], 'taxID' => $basketRow["taxID"], 'tax_rate' => $basketRow["tax_rate"]);
         try {
             $this->db->insert('s_order_details', $data);
         } catch (Exception $e) {
             throw new Enlight_Exception("##sOrder-sTemporaryOrder-Position-#02:" . $e->getMessage(), 0, $e);
         }
     }
     // For every article in basket
     return;
 }
Esempio n. 7
-1
 /**
  * @covers sBasket::sUpdateArticle
  */
 public function testsUpdateArticle()
 {
     // Null args, false result
     $this->assertFalse($this->module->sUpdateArticle(null, null));
     $this->module->sSYSTEM->sSESSION_ID = uniqid();
     $this->session->offsetSet('sessionId', $this->module->sSYSTEM->sSESSION_ID);
     // Get random article
     $randomArticle = $this->db->fetchRow('SELECT detail.articleID, detail.ordernumber
         FROM s_articles_details detail
         INNER JOIN s_articles article
           ON article.id = detail.articleID
         WHERE detail.active = 1
         ORDER BY RAND() LIMIT 1');
     $this->db->insert('s_order_basket', array('price' => 0.01, 'quantity' => 1, 'sessionID' => $this->session->get('sessionId'), 'ordernumber' => $randomArticle['ordernumber'], 'articleID' => $randomArticle['articleID']));
     $basketId = $this->db->lastInsertId();
     // Store previous amount
     $previousAmount = $this->module->sGetAmount();
     $this->assertEquals(array('totalAmount' => 0.01), $previousAmount);
     // Update the article, prices are recalculated
     $this->assertNull($this->module->sUpdateArticle($basketId, 1));
     $oneAmount = $this->module->sGetAmount();
     $this->assertGreaterThan($previousAmount['totalAmount'], $oneAmount['totalAmount']);
     // Update from 1 to 2, we should get a more expensive cart
     $this->assertNull($this->module->sUpdateArticle($basketId, 2));
     $twoAmount = $this->module->sGetAmount();
     $this->assertGreaterThanOrEqual($oneAmount['totalAmount'], $twoAmount['totalAmount']);
     $this->assertLessThanOrEqual(2 * $oneAmount['totalAmount'], $twoAmount['totalAmount']);
     // Housekeeping
     $this->db->delete('s_order_basket', array('sessionID = ?' => $this->session->get('sessionId')));
 }