Esempio n. 1
0
 /**
  * @param array $customer
  * @param string $table
  * @param string $key
  * @param array $dbFields
  * @return bool|array
  */
 private function createOrUpdate(array $customer, $table, $key, array $dbFields)
 {
     $id = is_numeric($key) ? $key : $customer[$key];
     if (empty($id)) {
         $insertFields = [];
         $insertValues = [];
         foreach ($dbFields as $dbField => $field) {
             if (isset($customer[$field])) {
                 $insertFields[] = $dbField;
                 $insertValues[] = $customer[$field];
             }
         }
         $sql = "INSERT INTO {$table} (" . implode(', ', $insertFields) . ")\n                    VALUES (" . implode(', ', $insertValues) . ")";
         $result = $this->db->query($sql);
         if ($result === false) {
             return false;
         }
         $customer[$key] = (int) $this->db->lastInsertId();
     } else {
         $updateData = [];
         foreach ($dbFields as $dbField => $field) {
             if (isset($customer[$field])) {
                 $updateData[] = $dbField . '=' . $customer[$field];
             }
         }
         if (count($updateData) > 1) {
             $updateData = implode(', ', $updateData);
             $sql = "\n                    UPDATE {$table} SET {$updateData}\n                    WHERE id = {$id}\n                ";
             $this->db->query($sql);
         }
     }
     return $customer;
 }
 /**
  * Creates a category and returns its id
  *
  * @param $description - category name
  * @param $id - id of the parent category
  * @param $path - category path
  *
  * @return int created category id
  */
 protected function insertCategory($description, $id, $path)
 {
     if ($id === null) {
         $this->isRootExists();
         $values = "(1, NULL, NOW(), NOW(), '{$description}', 1)";
     } else {
         $values = "({$id}, '{$path}', NOW(), NOW(), '{$description}', 1)";
     }
     $sql = "INSERT INTO s_categories (parent, path, added, changed, description, active)\n                VALUES {$values}";
     $this->db->exec($sql);
     $insertedId = $this->db->lastInsertId();
     return $insertedId;
 }
 /**
  * @param array $record
  * @return string
  */
 private function getSupplierId($record)
 {
     $this->suppliers = $this->getSuppliers();
     $name = $record['supplierName'];
     $supplierId = $this->suppliers[$name];
     //creates supplier if does not exists
     if (!$supplierId) {
         $data = array('name' => $name);
         $builder = $this->dbalHelper->getQueryBuilderForEntity($data, 'Shopware\\Models\\Article\\Supplier', false);
         $builder->execute();
         $supplierId = $this->db->lastInsertId();
         $this->suppliers[$name] = $supplierId;
     }
     return $supplierId;
 }
Esempio n. 4
0
 /**
  * @param array $linkData
  * @return bool|string
  */
 public function addArticleLink(array $linkData)
 {
     if (!($linkData['articleID'] = $this->getArticleID($linkData))) {
         return false;
     }
     if (empty($linkData) || !is_array($linkData) || empty($linkData['link']) || empty($linkData['description'])) {
         return false;
     }
     if (empty($linkData['target'])) {
         $linkData['target'] = '_blank';
     }
     $sql = 'INSERT INTO s_articles_information (articleID, description, link, target)
             VALUES (?, ?, ?, ?)';
     $this->db->query($sql, [$linkData['articleID'], $linkData['description'], $linkData['link'], $linkData['target']]);
     return $this->db->lastInsertId();
 }
Esempio n. 5
0
 /**
  * Save user shipping address.
  * Used internally in sAdmin during the registration process
  *
  * @param int $userID user id (s_user.id) from sSaveRegisterMain
  * @param array $userObject Array with all information from the registration process
  * @return int Created shipping address id
  */
 public function sSaveRegisterShipping($userID, $userObject)
 {
     $sqlShipping = "INSERT INTO s_user_shippingaddress\n            (userID, company, department, salutation, firstname, lastname,\n            street, zipcode, city, countryID, stateID, additional_address_line1, additional_address_line2)\n            VALUES\n            (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
     $sqlShipping = $this->eventManager->filter('Shopware_Modules_Admin_SaveRegisterShipping_FilterSql', $sqlShipping, array('subject' => $this, 'user' => $userObject, 'id' => $userID));
     $shippingParams = array($userID, $userObject["shipping"]["company"], $userObject["shipping"]["department"], $userObject["shipping"]["salutation"], $userObject["shipping"]["firstname"], $userObject["shipping"]["lastname"], $userObject["shipping"]["street"], $userObject["shipping"]["zipcode"], $userObject["shipping"]["city"], $userObject["shipping"]["country"], $userObject["shipping"]["stateID"], $userObject["shipping"]["additional_address_line1"], $userObject["shipping"]["additional_address_line2"]);
     // Trying to insert
     $saveUserData = $this->db->query($sqlShipping, $shippingParams);
     $this->eventManager->notify('Shopware_Modules_Admin_SaveRegisterShipping_Return', array('subject' => $this, 'insertObject' => $saveUserData));
     // New attributes table
     $shippingId = $this->db->lastInsertId();
     $sqlAttributes = "INSERT INTO s_user_shippingaddress_attributes\n                 (shippingID, text1, text2, text3, text4, text5, text6)\n                 VALUES\n                 (?, ?, ?, ?, ?, ?, ?)";
     $sqlAttributes = $this->eventManager->filter('Shopware_Modules_Admin_SaveRegisterShippingAttributes_FilterSql', $sqlAttributes, array('subject' => $this, 'user' => $userObject, 'id' => $userID));
     $attributeParams = array($shippingId, $userObject["shipping"]["text1"], $userObject["shipping"]["text2"], $userObject["shipping"]["text3"], $userObject["shipping"]["text4"], $userObject["shipping"]["text5"], $userObject["shipping"]["text6"]);
     $saveAttributeData = $this->db->query($sqlAttributes, $attributeParams);
     $this->eventManager->notify('Shopware_Modules_Admin_SaveRegisterShippingAttributes_Return', array('subject' => $this, 'insertObject' => $saveAttributeData));
     return $shippingId;
 }
Esempio n. 6
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. 7
0
 /**
  * save order shipping address
  * @access public
  */
 public function sSaveShippingAddress($address, $id)
 {
     $sql = "\n        INSERT INTO s_order_shippingaddress\n        (\n            userID,\n            orderID,\n            company,\n            department,\n            salutation,\n            firstname,\n            lastname,\n            street,\n            zipcode,\n            city,\n            countryID,\n            stateID,\n            additional_address_line1,\n            additional_address_line2\n        )\n        VALUES (\n            ?,\n            ?,\n            ?,\n            ?,\n            ?,\n            ?,\n            ?,\n            ?,\n            ?,\n            ?,\n            ?,\n            ?,\n            ?,\n            ?\n            )\n        ";
     $sql = $this->eventManager->filter('Shopware_Modules_Order_SaveShipping_FilterSQL', $sql, array('subject' => $this, 'address' => $address, 'id' => $id));
     $array = array($address["userID"], $id, $address["company"], $address["department"], $address["salutation"], $address["firstname"], $address["lastname"], $address["street"], $address["zipcode"], $address["city"], $address["countryID"], $address["stateID"], $address["additional_address_line1"], $address["additional_address_line2"]);
     $array = $this->eventManager->filter('Shopware_Modules_Order_SaveShipping_FilterArray', $array, array('subject' => $this, 'address' => $address, 'id' => $id));
     $result = $this->db->executeUpdate($sql, $array);
     //new attribute table
     $shippingId = $this->db->lastInsertId();
     $sql = "INSERT INTO s_order_shippingaddress_attributes (shippingID, text1, text2, text3, text4, text5, text6) VALUES (?,?,?,?,?,?,?)";
     $sql = $this->eventManager->filter('Shopware_Modules_Order_SaveShippingAttributes_FilterSQL', $sql, array('subject' => $this, 'address' => $address, 'id' => $id));
     $array = array($shippingId, $address["text1"], $address["text2"], $address["text3"], $address["text4"], $address["text5"], $address["text6"]);
     $array = $this->eventManager->filter('Shopware_Modules_Order_SaveShippingAttributes_FilterArray', $array, array('subject' => $this, 'address' => $address, 'id' => $id));
     $this->db->executeUpdate($sql, $array);
     return $result;
 }
Esempio n. 8
0
 /**
  * Save a new article comment / voting
  * Reads several values directly from _POST
  * @param int $article - s_articles.id
  * @throws Enlight_Exception
  * @return null
  */
 public function sSaveComment($article)
 {
     $request = $this->frontController->Request();
     $sVoteName = strip_tags($request->getPost('sVoteName'));
     $sVoteSummary = strip_tags($request->getPost('sVoteSummary'));
     $sVoteComment = strip_tags($request->getPost('sVoteComment'));
     $sVoteStars = doubleval($request->getPost('sVoteStars'));
     $sVoteMail = strip_tags($request->getPost('sVoteMail'));
     if ($sVoteStars < 1 || $sVoteStars > 10) {
         $sVoteStars = 0;
     }
     $sVoteStars = $sVoteStars / 2;
     if ($this->config['sVOTEUNLOCK']) {
         $active = 0;
     } else {
         $active = 1;
     }
     $sBADWORDS = "#sex|p**n|viagra|url\\=|src\\=|link\\=#i";
     if (preg_match($sBADWORDS, $sVoteComment)) {
         return false;
     }
     if (!empty($this->session['sArticleCommentInserts'][$article])) {
         $sql = '
             DELETE FROM s_articles_vote WHERE id=?
         ';
         $this->db->executeUpdate($sql, array($this->session['sArticleCommentInserts'][$article]));
     }
     $date = date("Y-m-d H:i:s");
     $sql = '
         INSERT INTO s_articles_vote (articleID, name, headline, comment, points, datum, active, email)
         VALUES (?, ?, ?, ?, ?, ?, ?, ?)
     ';
     $insertComment = $this->db->executeUpdate($sql, array($article, $sVoteName, $sVoteSummary, $sVoteComment, $sVoteStars, $date, $active, $sVoteMail));
     if (empty($insertComment)) {
         throw new Enlight_Exception("sSaveComment #00: Could not save comment");
     }
     $insertId = $this->db->lastInsertId();
     if (!isset($this->session['sArticleCommentInserts'])) {
         $this->session['sArticleCommentInserts'] = new ArrayObject();
     }
     $this->session['sArticleCommentInserts'][$article] = $insertId;
 }
Esempio n. 9
-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')));
 }