コード例 #1
0
ファイル: invoice.php プロジェクト: wardvanderput/SumoStore
 public function updateInvoice($invoiceID, $data)
 {
     // Delete invoice-lines and add 'em later again
     $this->query('DELETE FROM PREFIX_invoice_line WHERE invoice_id = :invoiceID', array('invoiceID' => $invoiceID));
     $this->query('DELETE FROM PREFIX_invoice_total WHERE invoice_id = :invoiceID', array('invoiceID' => $invoiceID));
     $totalTax = $total = 0;
     foreach ($data['amount'] as $line => $amount) {
         // Recalculate tax-amount based on the tax-percentage
         if ($data['tax_percentage'][$line] > 0) {
             $data['tax'][$line] = round($data['amount'][$line] * $data['quantity'][$line] * ($data['tax_percentage'][$line] / 100), 4);
             $totalTax += $data['tax'][$line];
         } else {
             $data['tax'][$line] = 0;
         }
         $total += $amount * $data['quantity'][$line];
         $this->query('INSERT INTO PREFIX_invoice_line (invoice_id, product_id, product, quantity, amount, tax_percentage, description) VALUES (
             :invoiceID,
             :productID,
             :product,
             :quantity,
             :amount,
             :taxPercentage,
             :description)', array('invoiceID' => $invoiceID, 'productID' => $data['product_id'][$line], 'product' => $data['product'][$line], 'quantity' => $data['quantity'][$line], 'amount' => $data['amount'][$line], 'taxPercentage' => $data['tax_percentage'][$line], 'description' => $data['description'][$line]));
     }
     foreach ($data['totals'] as $sortOrder => $productTotal) {
         $labelInject = isset($productTotal['label_inject']) ? $productTotal['label_inject'] : '';
         $this->query("INSERT INTO PREFIX_invoice_total\n                SET invoice_id        = :id,\n                    sort_order      = :sortOrder,\n                    label           = :label,\n                    label_inject    = :labelInject,\n                    value           = :value,\n                    value_hr        = :valueHR", array('id' => $invoiceID, 'sortOrder' => $sortOrder, 'label' => $productTotal['label'], 'labelInject' => $labelInject, 'value' => $productTotal['value'], 'valueHR' => Formatter::currency($productTotal['value'])));
     }
     // Totalamount is always the last line.
     $total = $productTotal['value'];
     $invoicePrefix = $this->config->get('invoice_prefix');
     // Customer country numeric? Change to plain text
     if (preg_match("/^\\d+\$/", $data['customer_country'])) {
         $countryData = $this->query("SELECT name FROM PREFIX_country WHERE country_id = :countryID", array('countryID' => $data['customer_country']))->fetch();
         $data['customer_country'] = !empty($countryData) ? $countryData['name'] : '-';
     }
     $this->query('UPDATE PREFIX_invoice SET
         invoice_no = :invoiceNO,
         customer_id = :customerID,
         customer_no = :customerNo,
         customer_name = :customerName,
         customer_address = :customerAddress,
         customer_postcode = :customerPostcode,
         customer_city = :customerCity,
         customer_country = :customerCountry,
         customer_email = :customerEmail,
         payment_amount = :paymentAmount,
         payment_tax_percentage = :paymentTax,
         shipping_amount = :shippingAmount,
         shipping_tax_percentage = :shippingTax,
         discount = :discount,
         total_amount = :amount,
         sent_date = :sentDate,
         notes = :notes,
         template = :template,
         term = :term,
         auto = :auto,
         reference = :reference
         WHERE invoice_id = :invoiceID', array('invoiceNO' => $invoicePrefix . str_pad($invoiceID, 5, 0, STR_PAD_LEFT), 'customerNo' => $customerNo, 'customerID' => $data['customer_id'], 'customerName' => $data['customer_name'], 'customerAddress' => $data['customer_address'], 'customerPostcode' => $data['customer_postcode'], 'customerCity' => $data['customer_city'], 'customerCountry' => $data['customer_country'], 'customerEmail' => $data['customer_email'], 'paymentAmount' => $data['payment_amount'], 'paymentTax' => $data['payment_tax'], 'shippingAmount' => $data['shipping_amount'], 'shippingTax' => $data['shipping_tax'], 'discount' => json_encode($data['discount']), 'amount' => $total, 'sentDate' => Formatter::dateReverse($data['sent_date']), 'notes' => $data['notes'], 'template' => $data['template'], 'term' => $data['term'], 'auto' => $data['auto'], 'reference' => $data['reference'], 'invoiceID' => $invoiceID));
 }
コード例 #2
0
ファイル: return.php プロジェクト: wardvanderput/SumoStore
 public function editReturn($return_id, $data)
 {
     $data['quantity'] = (int) $data['quantity'];
     $data['opened'] = (int) $data['opened'];
     $data['date_ordered'] = Formatter::dateReverse($data['date_ordered']);
     $data['return_id'] = $return_id;
     $this->query("UPDATE PREFIX_return\n            SET order_id            = :order_id,\n                product_id          = :product_id,\n                customer_id         = :customer_id,\n                firstname           = :firstname,\n                lastname            = :lastname,\n                telephone           = :telephone,\n                product             = :product,\n                model               = :model,\n                quantity            = :quantity,\n                opened              = :opened,\n                return_reason_id    = :return_reason_id,\n                return_action_id    = :return_action_id,\n                return_status_id    = :return_status_id,\n                comment             = :comment,\n                date_ordered        = :date_ordered,\n                date_modified       = NOW()\n            WHERE return_id         = :return_id", $data);
     Cache::removeAll();
 }
コード例 #3
0
ファイル: coupon.php プロジェクト: wardvanderput/SumoStore
 public function editCoupon($coupon_id, $data)
 {
     $this->query("UPDATE PREFIX_coupon\n            SET name        = :name,\n                code        = :code,\n                discount    = :discount,\n                tax_percentage = :tax_percentage,\n                type        = :type,\n                total       = :total,\n                logged      = :logged,\n                shipping    = :shipping,\n                date_start  = :date_start,\n                date_end    = :date_end,\n                uses_total  = :uses_total,\n                uses_customer = :uses_customer,\n                status      = :status\n            WHERE coupon_id = :id", array('name' => $data['name'], 'code' => $data['code'], 'discount' => (double) $data['discount'], 'tax_percentage' => (double) $data['tax_percentage'], 'type' => $data['type'], 'total' => (double) $data['total'], 'logged' => (int) $data['logged'], 'shipping' => (int) $data['shipping'], 'date_start' => Formatter::dateReverse($data['date_start']), 'date_end' => Formatter::dateReverse($data['date_end']), 'uses_total' => (int) $data['uses_total'], 'uses_customer' => (int) $data['uses_customer'], 'status' => (int) $data['status'], 'id' => $coupon_id));
     $this->query("DELETE FROM PREFIX_coupon_product WHERE coupon_id = " . (int) $coupon_id);
     if (isset($data['coupon_product'])) {
         foreach ($data['coupon_product'] as $product_id) {
             $this->query("INSERT INTO PREFIX_coupon_product SET coupon_id = " . (int) $coupon_id . ", product_id = " . (int) $product_id);
         }
     }
     $this->query("DELETE FROM PREFIX_coupon_category WHERE coupon_id = " . (int) $coupon_id);
     if (isset($data['coupon_category'])) {
         foreach ($data['coupon_category'] as $category_id) {
             $this->query("INSERT INTO PREFIX_coupon_category SET coupon_id = " . (int) $coupon_id . ", category_id = " . (int) $category_id);
         }
     }
 }
コード例 #4
0
ファイル: coupon.php プロジェクト: wardvanderput/SumoStore
 public function redeem($coupon_id, $order_id, $customer_id, $amount)
 {
     $this->query("INSERT INTO PREFIX_coupon_history\n            SET coupon_id       = :id,\n                customer_id     = :cid,\n                order_id        = :oid,\n                amount          = :amount,\n                date_added      = :date", array('id' => $coupon_id, 'cid' => $customer_id, 'oid' => $order_id, 'amount' => $amount, 'date' => Formatter::dateReverse(time())));
 }
コード例 #5
0
ファイル: product.php プロジェクト: wardvanderput/SumoStore
 public function editProduct($product_id, $data)
 {
     // stock & quantity
     if (isset($data['stock_product']) && !$data['stock_product'] || $data['stock_id'] == $product_id) {
         $data['stock_id'] = $product_id;
         $data['product_quantity'] = (int) $data['product_quantity'];
         if (!isset($data['stock_status_id'])) {
             $data['stock_status_id'] = 1;
         }
         $data['stock_status_id'] = (int) $data['stock_status_id'];
     } else {
         // Existing product as stock_id?
         $query = $this->query('SELECT product_id FROM PREFIX_product WHERE product_id = ' . (int) $data['stock_id'])->fetch();
         if ($query['product_id'] > 0) {
             $data['product_quantity'] = 'p2.quantity';
             $data['stock_status_id'] = 'p2.stock_status_id';
         } else {
             $data['stock_status_id'] = 1;
             $data['stock_id'] = $product_id;
             $data['product_quantity'] = (int) $data['product_quantity'];
         }
     }
     $data['product_price'] = str_replace(',', '.', $data['product_price']);
     $data['cost_price'] = str_replace(',', '.', $data['cost_price']);
     $this->query("UPDATE PREFIX_product\n            SET stock_id = :stock\n            WHERE product_id = :pid", array('stock' => $data['stock_id'], 'pid' => $product_id));
     $this->query("UPDATE PREFIX_product AS p\n            INNER JOIN PREFIX_product AS p2\n                ON p.stock_id = p2.product_id\n            SET p.model_2           = :model,\n                p.model_supplier    = :model_supplier,\n                p.location          = :location,\n                p.minimum           = :minimum,\n                p.subtract          = :subtract,\n                p.quantity          = :quantity,\n                p.stock_status_id   = :stock_status_id,\n                p.stock_id          = :stock_id,\n                p.stock_visible     = :stock_visible,\n                p.date_available    = :date_available,\n                p.manufacturer_id   = :manufacturer_id,\n                p.shipping          = :shipping,\n                p.price             = :price,\n                p.cost_price        = :cost_price,\n                p.points            = :points,\n                p.weight            = :weight,\n                p.weight_class_id   = :wclass_id,\n                p.length            = :length,\n                p.width             = :width,\n                p.height            = :height,\n                p.length_class_id   = :lclass_id,\n                p.status            = :status,\n                p.tax_percentage    = :tax_percentage,\n                p.date_modified     = :modified\n            WHERE p.product_id      = :product_id", array('model' => $data['model_2'], 'model_supplier' => $data['model_supplier'], 'location' => $data['location'], 'minimum' => $data['minimum'], 'subtract' => $data['subract'], 'quantity' => $data['product_quantity'], 'stock_status_id' => $data['stock_status_id'], 'stock_id' => $data['stock_id'], 'stock_visible' => $data['stock_visible'], 'date_available' => Formatter::dateReverse($data['date_available']), 'manufacturer_id' => $data['manufacturer_id'], 'shipping' => $data['shipping'], 'price' => $data['product_price'], 'cost_price' => $data['cost_price'], 'points' => $data['product_points'], 'weight' => $data['product_weight'], 'wclass_id' => $data['weight_class_id'], 'length' => $data['length'], 'lclass_id' => $data['length_class_id'], 'height' => $data['height'], 'width' => $data['width'], 'status' => $data['status'], 'tax_percentage' => $data['tax_percentage'], 'modified' => date('Y-m-d H:i:s'), 'product_id' => $product_id));
     $info_types = array('sku', 'upc', 'ean', 'jan', 'isbn', 'mpn');
     foreach ($info_types as $type) {
         if (isset($data[$type])) {
             if (!isset($data[$type . '_visible'])) {
                 $data[$type . '_visible'] = 0;
             }
             $this->query("\n                    UPDATE PREFIX_product\n                    SET " . $type . " = :var,\n                        " . $type . "_visible = " . (int) $data[$type . '_visible'] . "\n                    WHERE product_id = :pid", array('pid' => $product_id, 'var' => !empty($data[$type]) ? $data[$type] : ''));
         }
     }
     if (!isset($data['sort_order'])) {
         $sort_order = 0;
         // Get highest sort order for all categories
         foreach ($data['product_category'] as $k => $category_id) {
             $row = $this->query("\n                    SELECT MAX(sort_order) AS sort_order\n                    FROM PREFIX_product p\n                    LEFT JOIN PREFIX_product_to_category AS ptc\n                        ON ptc.product_id = p.product_id\n                    WHERE ptc.category_id = " . $category_id)->fetch();
             if ($row['sort_order'] > $sort_order) {
                 $sort_order = $row['sort_order'];
             }
         }
         $this->query("\n                UPDATE PREFIX_product\n                SET sort_order = " . (int) ($sort_order + 1) . "\n                WHERE product_id = " . (int) $product_id);
     }
     // Delete existing url-aliases (this may cause SEO-issues, investigate that a bit...)
     $this->query("DELETE FROM PREFIX_url_alias WHERE `query` = 'product_id=" . $product_id . "'");
     $this->query("DELETE FROM PREFIX_product_description WHERE product_id = " . (int) $product_id);
     foreach ($data['product_description'] as $language_id => $value) {
         unset($value['keyword']);
         $value['product_id'] = $product_id;
         $value['language_id'] = $language_id;
         $this->query("\n                INSERT INTO PREFIX_product_description\n                SET product_id      = :product_id,\n                    language_id     = :language_id,\n                    name            = :name,\n                    title           = :title,\n                    meta_keyword    = :meta_keyword,\n                    meta_description = :meta_description,\n                    description     = :description,\n                    tag             = :tag", $value);
         foreach (array_unique($data['product_category']) as $category_id) {
             foreach (array_unique($data['product_store']) as $store_id) {
                 Formatter::generateSeoURL($value['name'], 'product_id', $product_id, $language_id, $store_id, $category_id);
             }
         }
     }
     $this->query("DELETE FROM PREFIX_product_to_store WHERE product_id = " . (int) $product_id);
     $this->query("DELETE FROM PREFIX_product_to_category WHERE product_id = " . (int) $product_id);
     foreach (array_unique($data['product_category']) as $category_id) {
         $this->query("\n                INSERT INTO PREFIX_product_to_category\n                SET product_id  = " . (int) $product_id . ",\n                    category_id = " . (int) $category_id);
     }
     foreach (array_unique($data['product_store']) as $store_id) {
         $this->query("\n                INSERT INTO PREFIX_product_to_store\n                SET product_id  = " . (int) $product_id . ",\n                    store_id    = " . (int) $store_id);
     }
     $this->query("DELETE FROM PREFIX_product_attribute WHERE product_id = " . (int) $product_id);
     if (!empty($data['attribute']) && is_array($data['attribute'])) {
         $this->load->model('catalog/attribute');
         foreach ($data['attribute'] as $attributeID) {
             // Get attribute info
             $attributeInfo = $this->model_catalog_attribute->getAttributeDescriptions($attributeID);
             if (!empty($attributeInfo) && is_array($attributeInfo)) {
                 foreach ($attributeInfo as $languageID => $attributeDescription) {
                     $this->query("\n                            INSERT INTO PREFIX_product_attribute\n                            SET product_id  = " . (int) $product_id . ",\n                                attribute_id    = " . (int) $attributeID . ",\n                                language_id     = " . (int) $languageID . ",\n                                text            = :text", array('text' => $attributeDescription['name']));
                 }
             }
         }
     }
     $this->query("DELETE FROM PREFIX_product_option_value_description WHERE value_id IN (SELECT value_id FROM PREFIX_product_option_value WHERE option_id IN (SELECT option_id FROM PREFIX_product_option WHERE product_id = " . (int) $product_id . "))");
     $this->query("DELETE FROM PREFIX_product_option_value WHERE option_id IN (SELECT option_id FROM PREFIX_product_option WHERE product_id = " . (int) $product_id . ")");
     $this->query("DELETE FROM PREFIX_product_option_description WHERE option_id IN (SELECT option_id FROM PREFIX_product_option WHERE product_id = " . (int) $product_id . ")");
     $this->query("DELETE FROM PREFIX_product_option WHERE product_id = " . (int) $product_id);
     if (isset($data['product_option'])) {
         foreach ($data['product_option'] as $productOption) {
             if (!empty($productOption['option_description'][$this->config->get('language_id')]['name'])) {
                 $this->query("INSERT INTO PREFIX_product_option SET\n                        product_id = :productID,\n                        type = :type,\n                        sort_order = 0", array('productID' => $product_id, 'type' => $productOption['type']));
                 $optionID = $this->lastInsertId();
                 // Insert translations
                 foreach ($productOption['option_description'] as $languageID => $productOptionDescription) {
                     $this->query("INSERT INTO PREFIX_product_option_description SET\n                            option_id = :optionID,\n                            language_id = :languageID,\n                            name = :name", array('optionID' => $optionID, 'languageID' => $languageID, 'name' => $productOptionDescription['name']));
                 }
                 // Insert values (if applicable)
                 if (in_array($productOption['type'], array('select', 'radio', 'checkbox')) && isset($productOption['product_option_value'])) {
                     foreach ($productOption['product_option_value'] as $productOptionValue) {
                         if (!empty($productOptionValue['option_value_description'][$this->config->get('language_id')]['name'])) {
                             // We want to store the price excluding the tax. Why? The Dutch government likes to change tax
                             // rates. So! Store as ex-tax, show as inc-tax.
                             // Make sure commas are replaced with decimal points
                             $productOptionValue['price'] = str_replace(',', '.', $productOptionValue['price']);
                             $productOptionValue['weight'] = str_replace(',', '.', $productOptionValue['weight']);
                             $productOptionValue['price'] = round(floatval($productOptionValue['price']) / (1 + $data['tax_percentage'] / 100), 4);
                             $this->query("INSERT INTO PREFIX_product_option_value SET\n                                    option_id = :optionID,\n                                    active = :active,\n                                    quantity = :quantity,\n                                    subtract = :subtract,\n                                    price = :price,\n                                    price_prefix = :pricePrefix,\n                                    weight = :weight,\n                                    weight_prefix = :weightPrefix", array('optionID' => $optionID, 'active' => $productOptionValue['active'], 'quantity' => $productOptionValue['quantity'], 'subtract' => $productOptionValue['subtract'], 'price' => $productOptionValue['price'], 'pricePrefix' => $productOptionValue['price_prefix'], 'weight' => $productOptionValue['weight'], 'weightPrefix' => $productOptionValue['weight_prefix']));
                             $valueID = $this->lastInsertId();
                             // Insert translations
                             foreach ($productOptionValue['option_value_description'] as $languageID => $productOptionValueDescription) {
                                 $this->query("INSERT INTO PREFIX_product_option_value_description SET\n                                        value_id = :valueID,\n                                        language_id = :languageID,\n                                        name = :name", array('valueID' => $valueID, 'languageID' => $languageID, 'name' => $productOptionValueDescription['name']));
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->query("DELETE FROM PREFIX_product_discount WHERE product_id = " . (int) $product_id);
     if (isset($data['product_discount']) && count($data['product_discount'])) {
         foreach ($data['product_discount'] as $list) {
             if (empty($list['customer_group_id'])) {
                 continue;
             }
             if (empty($list['customer_group_id'])) {
                 $list['customer_group_id'] = 0;
             }
             $this->db->query("\n                    INSERT INTO PREFIX_product_discount\n                    SET product_id          = :product_id,\n                        customer_group_id   = :customer_group_id,\n                        quantity            = :quantity,\n                        priority            = :priority,\n                        price               = :price,\n                        date_start          = :date_start\n                        date_end            = :date_end", array('product_id' => $product_id, 'customer_group_id' => $list['customer_group_id'], 'quantity' => $list['quantity'], 'priority' => $list['priority'], 'price' => $list['price'], 'date_start' => Formatter::dateReverse($list['date_start']), 'date_end' => Formatter::dateReverse($list['date_end'])));
         }
     }
     $this->query("DELETE FROM PREFIX_product_special WHERE product_id = " . (int) $product_id);
     if (isset($data['product_special'])) {
         foreach ($data['product_special'] as $list) {
             if (empty($list['customer_group_id'])) {
                 continue;
             }
             if (empty($list['priority'])) {
                 $list['priority'] = 1;
             }
             $this->query("\n                    INSERT INTO PREFIX_product_special\n                    SET product_id          = :product_id,\n                        customer_group_id   = :customer_group_id,\n                        priority            = :priority,\n                        price               = :price,\n                        date_start          = :date_start,\n                        date_end            = :date_end", array('product_id' => $product_id, 'customer_group_id' => $list['customer_group_id'], 'priority' => $list['priority'], 'price' => $list['price'], 'date_start' => Formatter::dateReverse($list['date_start']), 'date_end' => Formatter::dateReverse($list['date_end'])));
         }
     }
     $this->query("DELETE FROM PREFIX_product_image WHERE product_id = " . (int) $product_id);
     if (isset($data['product_image']) && sizeof($data['product_image']) > 0) {
         foreach ($data['product_image'] as $i => $product_image) {
             if ($i == 0) {
                 $this->query("\n                        UPDATE PREFIX_product\n                        SET image = :image\n                        WHERE product_id = " . (int) $product_id, array('image' => $product_image));
             } else {
                 $this->query("\n                        INSERT INTO PREFIX_product_image\n                        SET product_id = " . (int) $product_id . ",\n                            image = :name,\n                            sort_order = " . ($i + 1), array('name' => $product_image));
             }
         }
     } else {
         // Remove main image
         $this->query("UPDATE PREFIX_product SET image = '' WHERE product_id = " . (int) $product_id);
     }
     $this->query("DELETE FROM PREFIX_product_to_download WHERE product_id = " . (int) $product_id);
     if (isset($data['product_download'])) {
         foreach ($data['product_download'] as $download_id) {
             $this->query("\n                    INSERT INTO PREFIX_product_to_download\n                    SET product_id = " . (int) $product_id . ",\n                        download_id = " . (int) $download_id);
         }
     }
     $this->query("DELETE FROM PREFIX_product_related WHERE product_id = '" . (int) $product_id . "'");
     if (isset($data['product_related'])) {
         foreach ($data['product_related'] as $related_id) {
             $this->query("INSERT INTO PREFIX_product_related SET product_id = " . (int) $product_id . ", related_id = " . (int) $related_id);
         }
     }
     Cache::removeAll();
 }
コード例 #6
0
ファイル: coupon.php プロジェクト: wardvanderput/SumoStore
 protected function validateForm()
 {
     if (utf8_strlen($this->request->post['name']) < 3 || utf8_strlen($this->request->post['name']) > 128) {
         $this->error['name'] = Language::getVar('SUMO_ERROR_NAME');
     }
     if (utf8_strlen($this->request->post['code']) < 3 || utf8_strlen($this->request->post['code']) > 50) {
         $this->error['code'] = Language::getVar('SUMO_ERROR_CODE');
     }
     if (!empty($this->request->post['date_start']) && !empty($this->request->post['date_end']) && strtotime(Formatter::dateReverse($this->request->post['date_end'])) < strtotime(Formatter::dateReverse($this->request->post['date_start']))) {
         $this->error[] = Language::getVar('SUMO_ERROR_DATE_END_BEFORE_START');
     }
     $coupon_info = $this->model_sale_coupon->getCouponByCode($this->request->post['code']);
     if ($coupon_info) {
         if (!isset($this->request->get['coupon_id'])) {
             $this->error['warning'] = Language::getVar('SUMO_ERROR_CODE_EXISTS');
         } elseif ($coupon_info['coupon_id'] != $this->request->get['coupon_id']) {
             $this->error['warning'] = Language::getVar('SUMO_ERROR_CODE_EXISTS');
         }
     }
     if (!$this->error) {
         return true;
     }
     return false;
 }
コード例 #7
0
ファイル: customer.php プロジェクト: wardvanderput/SumoStore
 public function addHistory($customer_id, $comment)
 {
     if (!empty($comment)) {
         $this->query("INSERT INTO PREFIX_customer_history\n                SET customer_id     = :customer_id,\n                    comment         = :comment,\n                    date_added      = :date_added", array('customer_id' => $customer_id, 'comment' => strip_tags($comment), 'date_added' => Formatter::dateReverse(time())));
         Cache::removeAll();
     }
 }
コード例 #8
0
ファイル: special.php プロジェクト: wardvanderput/SumoStore
 protected function validateForm($data)
 {
     // Set new product price
     $this->load->model('catalog/product');
     $productData = $this->model_catalog_product->getProduct($data['product_id']);
     if (!$productData) {
         $this->data['error'] = Language::getVar('SUMO_ERROR_NO_PRODUCT_FOR_DISCOUNT');
         return false;
     }
     $this->request->post['price'] = $productData['price'];
     // Comma's, decimals..
     $data['discount'] = str_replace(',', '.', $data['discount']);
     if (mb_substr(trim($data['discount']), -1) == '%') {
         $discount = trim($data['discount']);
         $discount = mb_substr($discount, 0, mb_strlen($discount) - 1);
         $discount = floatval($discount);
         if ($discount <= 100) {
             $data['price'] = $productData['price'] - $productData['price'] * ($discount / 100);
         }
         $data['discount_suffix'] = '%';
     } else {
         if (floatval($data['discount']) > $productData['price']) {
             $data['price'] = 0;
         } else {
             $data['price'] = $productData['price'] - floatval($data['discount']);
         }
         // Amount, no suffix necessary
         $data['discount_suffix'] = '';
     }
     // Check if dates are correct
     $data['date_start'] = Formatter::dateReverse($data['date_start']);
     $data['date_end'] = Formatter::dateReverse($data['date_end']);
     if (strtotime($data['date_end']) < strtotime($data['date_start'])) {
         $this->data['error'] = Language::getVar('SUMO_ERROR_END_BEFORE_START');
         return false;
     }
     return $data;
 }
コード例 #9
0
ファイル: generate.php プロジェクト: wardvanderput/SumoStore
 private function getDataProductSales($filters)
 {
     $cache = 'report.products.sales.' . json_encode($filters);
     $data = Cache::find($cache);
     if (is_array($data) && count($data)) {
         //return $data;
     }
     $sql = "SELECT * FROM PREFIX_orders_lines AS ol LEFT JOIN PREFIX_orders AS o ON o.order_id = ol.order_id";
     if (!empty($filters['date_start'])) {
         $sql .= " AND DATE(order_date) >= '" . Formatter::dateReverse($filters['date_start']) . "'";
     }
     if (!empty($filters['date_end'])) {
         $sql .= " AND DATE(order_date) <= '" . Formatter::dateReverse($filters['date_end']) . "'";
     }
     if (isset($filters['start']) && !empty($filters['limit'])) {
         if ($filters['start'] < 1) {
             $filters['start'] = 0;
         }
     }
     $return = $temp = array();
     $products = $this->fetchAll($sql);
     $i = 0;
     foreach ($products as $list) {
         //$list = json_decode($list['data'], true);
         $check = $this->query("SELECT viewed FROM PREFIX_product WHERE product_id = :id", array('id' => $list['product_id']))->fetch();
         if (empty($check['viewed'])) {
             $check['viewed'] = 0;
         }
         $poc = $list['name'] . $list['product_id'];
         if (!isset($temp[$poc])) {
             $temp[$poc] = array(0 => $list['name'], 1 => !empty($list['model']) ? $list['model'] : 'P' . $list['product_id'], 2 => $check['viewed'], 3 => 0, 4 => 0);
         }
         $temp[$poc][3] += $list['quantity'];
         $temp[$poc][4] += $list['price'] * $list['quantity'];
     }
     $quantity = $total = array();
     foreach ($temp as $key => $row) {
         $quantity[$key] = $row[3];
         $total[$key] = $row[4];
     }
     unset($products);
     array_multisort($quantity, SORT_DESC, $total, SORT_DESC, $temp);
     unset($quantity);
     unset($total);
     if (isset($filters['start']) && !empty($filters['limit'])) {
         $return = array_slice($temp, $filters['start'], $filters['limit']);
     } else {
         return count($temp);
     }
     foreach ($return as $key => $list) {
         $return[$key][4] = Formatter::currency($list[4]);
         $return[$key][5] = round($list[3] / $list[2] * 100, 2) . '%';
     }
     Cache::set($cache, $return);
     return $return;
 }
コード例 #10
0
ファイル: return.php プロジェクト: wardvanderput/SumoStore
 public function addReturn($data)
 {
     //$returnStatusID = (int)$this->config->get('return_status_id');
     $returnStatusID = 1;
     $this->query("INSERT INTO PREFIX_return SET \n            order_id = :orderID, \n            customer_id = :customerID,\n            firstname = :firstname,\n            lastname = :lastname,\n            email = :email,\n            telephone = :telephone,\n            product = :product,\n            product_id = :productID,\n            model = :model,\n            quantity = :quantity,\n            opened = :opened,\n            return_reason_id = :returnReasonID,\n            return_status_id = :returnStatusID, \n            comment = :comment, \n            date_ordered = :dateOrdered, \n            date_added = NOW(), \n            date_modified = NOW()", array('orderID' => $data['order_id'], 'customerID' => (int) $this->customer->getId(), 'firstname' => $data['firstname'], 'lastname' => $data['lastname'], 'email' => $data['email'], 'telephone' => $data['telephone'], 'product' => $data['product'], 'productID' => $data['product_id'], 'model' => $data['model'], 'quantity' => $data['quantity'], 'opened' => $data['opened'], 'returnReasonID' => $data['return_reason_id'], 'returnStatusID' => $returnStatusID, 'comment' => $data['comment'], 'dateOrdered' => Formatter::dateReverse($data['date_ordered'])));
 }
コード例 #11
0
ファイル: review.php プロジェクト: wardvanderput/SumoStore
 public function editReview($reviewID, $data)
 {
     $this->query("UPDATE PREFIX_review SET\n            author = :author,\n            product_id = :productID,\n            text = :text,\n            rating = :rating,\n            status = :status,\n            date_added = :dateAdded,\n            date_modified = NOW()\n            WHERE review_id = :reviewID", array('reviewID' => $reviewID, 'author' => $data['author'], 'productID' => $data['product_id'], 'text' => strip_tags($data['text']), 'rating' => $data['rating'], 'status' => $data['status'], 'dateAdded' => Formatter::dateReverse($data['date_added'])));
     Cache::removeAll();
 }