コード例 #1
0
ファイル: cms.php プロジェクト: wardvanderput/SumoStore
 public function saveBlog($store_id, $input, $blog_id = 0)
 {
     if (!$blog_id) {
         $this->query("INSERT INTO PREFIX_blog SET create_time = :date", array('date' => date('Y-m-d H:i:s')));
         $blog_id = $this->lastInsertId();
     }
     $this->query("UPDATE PREFIX_blog\n            SET store_id    = :store,\n                author      = :author,\n                update_time = :update,\n                publish_date= :publish\n            WHERE blog_id   = :id", array('store' => $store_id, 'author' => $input['author'], 'update' => date('Y-m-d H:i:s'), 'publish' => date('Y-m-d H:i:s', strtotime($input['publish_date'])), 'id' => $blog_id));
     $this->query("DELETE FROM PREFIX_blog_description WHERE blog_id = :id", array('id' => $blog_id));
     $this->query("DELETE FROM PREFIX_url_alias WHERE query = :query", array('query' => 'blog_id=' . $blog_id));
     foreach ($input['description'] as $lang => $list) {
         $this->query("INSERT INTO PREFIX_blog_description\n                SET language_id     = :lang,\n                    title           = :title,\n                    intro_text      = :intro,\n                    text            = :text,\n                    meta_description= :meta,\n                    meta_keyword    = :keys,\n                    blog_id  = :id", array('id' => $blog_id, 'lang' => $lang, 'title' => $list['title'], 'intro' => $list['intro_text'], 'text' => $list['text'], 'meta' => $list['meta_description'], 'keys' => $list['meta_keyword']));
         Formatter::generateSeoURL($list['title'], 'blog_id', $blog_id, $lang, $store_id);
     }
     Cache::removeAll();
     return $blog_id;
 }
コード例 #2
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();
 }