Rodney Enciso Arias 7 лет назад
Сommit
a275d47d26

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+# from . import product


+ 33 - 0
__openerp__.py

@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+{
+    "name": "Website Sale Multi Add",
+    "summary": """Allows to disable product sales via eCommerce for any reason""",
+    "category": "eCommerce",
+    "images": [],
+    "version": "1.0.0",
+
+    "author": "IT-Projects LLC, Ivan Yelizariev",
+    "website": "https://it-projects.info",
+    "license": "GPL-3",
+    # "price": 9.00,
+    # "currency": "EUR",
+
+    "depends": [
+        "website_sale",
+    ],
+    "external_dependencies": {"python": [], "bin": []},
+    "data": [
+        # "views.xml",
+        "templates.xml",
+    ],
+    "qweb": [
+    ],
+    "demo": [
+    ],
+
+    "post_load": None,
+    "pre_init_hook": None,
+    "post_init_hook": None,
+    "installable": True,
+    "auto_install": False,
+}

+ 9 - 0
product.py

@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+from openerp import fields
+from openerp import models
+
+
+# class ProductTemplate(models.Model):
+#     _inherit = 'product.template'
+#
+#     sale_on_website = fields.Boolean('Show Add To Cart button', help='Switch off to disable sales via eCommerce', default=True)

BIN
static/description/icon.png


+ 10 - 0
static/src/css/website_sale_add_to_cart_disable.css

@@ -0,0 +1,10 @@
+.oe_product form.disable_to_order a.a-submit{
+	display:none;
+}
+
+#product_detail.disable_to_order #add_to_cart{
+	display:none;
+}
+#product_detail.disable_to_order .css_quantity{
+	display:none;
+}

+ 81 - 0
static/src/js/website_sale_multi_add.js

@@ -0,0 +1,81 @@
+$('.js_variant_change').click(function(e) {
+    var attributeList = $('#attribute_list').val();
+    var target = $(e.currentTarget).prop('id');
+    var attribute_id = target.substring(target.indexOf('_') + 1);
+    var indexOfValue = attributeList.indexOf('[' + attribute_id +
+        ']');
+    var buffer = '';
+
+    for (i = indexOfValue - 2; i > 0; i--) {
+        var charValue = attributeList.charAt(i);
+
+        if (charValue == '[') {
+            break;
+        }
+
+        if ($.isNumeric(charValue)) {
+            buffer = attributeList.charAt(i) + buffer;
+        }
+    }
+    $('.product_id').val(buffer);
+    $(this).closest('form').submit();
+});
+
+$('#curva').off('click').click(function(e) {
+    var attributeList = $('#attribute_list').val();
+    var variantList = $('#variant_list').val();
+    var variant = variantList.substring(variantList.indexOf('('));
+    var indexOfValue;
+    var buffer;
+    var valor;
+    var array_ids = [];
+    // var productCurva = $('#product_curva').val();
+    var productCurva = $('#product_curva_qty').val().split(",");
+    console.log(productCurva);
+    // console.log(productCurva);
+    for (i = 1; i < variant.length - 1; i++) {
+        valor = variant[i];
+        if (valor == ',') {
+            continue;
+        } else {
+            if (valor == ' ') {
+                continue;
+            }
+        }
+        indexOfValue = attributeList.indexOf('[' + valor + ']');
+        buffer = '';
+        for (j = indexOfValue - 2; j >= 0; j--) {
+            var charValue = attributeList.charAt(j);
+            if (charValue == '[') {
+                break;
+            }
+            if ($.isNumeric(charValue)) {
+                buffer = attributeList.charAt(j) + buffer;
+            }
+        }
+        var number = parseInt(buffer);
+        array_ids.push(number);
+    }
+    array_ids.sort(function(a, b) {
+        return a - b
+    });
+    console.log(array_ids);
+    for (var j = 0; j < array_ids.length; j++) {
+        var add_qty = productCurva[j];
+        // if (productCurva == 'c1') {
+            if (j == 0 || j == array_ids.length - 1) {
+                add_qty = 1;
+            }
+            var data = '&product_id=' + array_ids[j] + '&add_qty=' + add_qty;
+        // }
+        console.log(data);
+        $.ajax({
+            url: '/shop/cart/update',
+            type: 'POST',
+            async: false,
+            data: data,
+        });
+    }
+    window.location.reload();
+    return false;
+});

+ 155 - 0
templates.xml

@@ -0,0 +1,155 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <template id="assets_frontend" inherit_id="website.assets_frontend" name="Shop">
+            <xpath expr="." position="inside">
+                <script type="text/javascript" src="/website_sale_multi_add/static/src/js/website_sale_multi_add.js"></script>
+                <!-- <link rel='stylesheet' href='/website_sale_stock_status/static/src/css/website_sale_stock_status.css'/> -->
+            </xpath>
+        </template>
+
+        <template id="variant_form" inherit_id="website_sale.variants" name="variants">
+            <xpath expr="//t[@t-as='variant_id']" position="replace">
+                <t t-foreach="product.attribute_line_ids" t-as="variant_id">
+                    <li t-if="len(variant_id.value_ids) &gt; 1">
+                        <t t-if="variant_id.attribute_id.type in ['select', 'hidden']">
+                            <select class="form-control js_variant_change" t-att-name="'attribute-%s-%s' % (product.id, variant_id.attribute_id.id)">
+                                <t t-foreach="variant_id.value_ids" t-as="value_id">
+                                    <option t-att-value="value_id.id">
+                                        <span t-field="value_id.name"/>
+                                        <span t-if="value_id.price_extra">
+                                            <t t-esc="value_id.price_extra &gt; 0 and '+' or ''"/><span
+                                                t-field="value_id.price_extra"
+                                                style="white-space: nowrap;"
+                                                t-field-options="{                                &quot;widget&quot;: &quot;monetary&quot;,                                 &quot;from_currency&quot;: &quot;product.company_id.currency_id&quot;,                                &quot;display_currency&quot;: &quot;user_id.partner_id.property_product_pricelist.currency_id&quot;                            }"/>
+                                        </span>
+                                    </option>
+                                </t>
+                            </select>
+                        </t>
+
+                        <t t-if="user_id.partner_id.website_sale_type == True">
+                            <div class="container">
+                                <div class="row">
+                                    <div class="col-md-12">
+                                        <div class="panel panel-primary">
+                                            <div class="panel-heading">
+                                                <h3 class="panel-title" t-field="variant_id.attribute_id.name"></h3>
+                                            </div>
+                                            <table class="table table-condenced text-center">
+                                                <t t-if="variant_id.attribute_id.type == 'radio'">
+                                                    <ul class="list-unstyled">
+                                                        <t t-set="inc" t-value="0"/>
+                                                        <tr>
+                                                            <t t-foreach="variant_id.value_ids" t-as="value_id">
+                                                                <li class="form-group js_attribute_value">
+                                                                        <td>
+                                                                            <span t-field="value_id.name"/>
+                                                                        </td>
+                                                                </li>
+                                                            <t t-set="inc" t-value="inc+1"/></t>
+                                                        </tr>
+                                                    </ul>
+                                                </t>
+                                            </table>
+                                        </div>
+                                    </div>
+                                </div>
+                            </div>
+                        </t>
+
+
+                        <input id="attribute_list" type="hidden" t-att-value="attribute_value_ids"></input>
+                        <input id="variant_list" type="hidden" t-att-value="variant_id.value_ids"></input>
+                        <input id="product_curva" type="hidden" t-att-value="product.variant_item_ids"/>
+                        <input id="product_curva_qty" type="hidden" t-att-value="product.curva"/>
+                        <t t-if="user_id.partner_id.website_sale_type == False">
+                            <div class="container">
+                                <div class="row text-left">
+                                    <div class="col-md-12">
+                                        <div class="pricing-table">
+                                            <div class="panel panel-dafault" style="border:none;">
+                                                <div class="panel-body panel-body-landing">
+                                                    <table class="table table-condenced text-center">
+                                                        <t t-if="variant_id.attribute_id.type == 'radio'">
+                                                            <ul class="list-unstyled">
+                                                                <t t-set="inc" t-value="0"/>
+                                                                <t t-foreach="variant_id.value_ids" t-as="value_id">
+                                                                    <li class="form-group js_attribute_value">
+                                                                        <tr>
+                                                                            <td>
+                                                                                <span t-field="value_id.name"/>
+                                                                            </td>
+                                                                            <td>
+                                                                                <span class="badge" t-if="value_id.price_extra">
+                                                                                    <t t-esc="value_id.price_extra &gt; 0 and '+' or ''"/>
+                                                                                    <span t-field="value_id.price_extra" t-field-options="{                                       &quot;widget&quot;: &quot;monetary&quot;,                                       &quot;from_currency&quot;: &quot;product.company_id.currency_id&quot;,                                       &quot;display_currency&quot;: &quot;user_id.partner_id.property_product_pricelist.currency_id&quot;                                    }"/></span>
+                                                                            </td>
+                                                                            <td>
+                                                                                <button t-att-id="'attribute_%s' % value_id.id" type="button" class="js_variant_change btn btn-primary" t-att-checked="'checked' if not inc else ''" t-att-name="'attribute-%s-%s' % (product.id, variant_id.attribute_id.id)" t-att-value="inc+1">Agregar al carro</button>
+                                                                            </td>
+                                                                        </tr>
+                                                                    </li>
+                                                                <t t-set="inc" t-value="inc+1"/></t>
+                                                            </ul>
+                                                        </t>
+                                                    </table>
+                                                </div>
+                                            </div>
+                                        </div>
+                                    </div>
+                                </div>
+                            </div>
+                        </t>
+                        <t t-if="variant_id.attribute_id.type == 'color'">
+                            <ul class="list-inline">
+                                <t t-set="inc" t-value="0"/>
+                                <li t-foreach="variant_id.value_ids" t-as="value_id">
+                                    <label t-attf-style="background-color:#{value_id.color or value_id.name}" t-attf-class="css_attribute_color #{'active' if not inc else ''}">
+                                        <input type="radio" class="js_variant_change" t-att-checked="'checked' if not inc else ''" t-att-name="'attribute-%s-%s' % (product.id, variant_id.attribute_id.id)" t-att-value="value_id.id" t-att-title="value_id.name"/>
+                                    </label>
+                                    <t t-set="inc" t-value="inc+1"/>
+                                </li>
+                            </ul>
+                        </t>
+                    </li>
+                    <t t-if="user_id.partner_id.website_sale_type == True">
+                        <div class="container text-center">
+                            <button id="curva" class="btn btn-primary" href="">Comprar Curva</button>
+                        </div>
+                    </t>
+                </t>
+            </xpath>
+        </template>
+
+        <template id="product_form" inherit_id="website_sale.product" name="product">
+            <xpath expr="//a[@id='add_to_cart']" position="replace">
+                <!-- <t t-foreach="product.attribute_line_ids" t-as="variant_id">
+                    <t t-if="len(variant_id.value_ids) &gt; 1"> -->
+                        <a id="add_to_cart" class="btn btn-primary btn-lg mt8 js_check_product a-submit" href="#" style="display:none;">Add to Cart</a>
+                    <!-- </t>
+                </t> -->
+            </xpath>
+        </template>
+
+        <template id="product_quantity_form" inherit_id="website_sale.product_quantity" name="product_quantity">
+            <xpath expr="//div[@class='css_quantity input-group oe_website_spinner']" position="replace">
+
+                <div class="css_quantity input-group oe_website_spinner" style="display:none;">
+                    <span class="input-group-addon">
+                        <a t-attf-href="#" class="mb8 js_add_cart_json">
+                            <i class="fa fa-minus"/>
+                        </a>
+                    </span>
+                    <input type="text" class="js_quantity form-control" data-min="1" name="add_qty" value="1"/>
+                    <span class="input-group-addon">
+                        <a t-attf-href="#" class="mb8 float_left js_add_cart_json">
+                            <i class="fa fa-plus"/>
+                        </a>
+                    </span>
+                </div>
+
+            </xpath>
+        </template>
+    </data>
+</openerp>

+ 15 - 0
views.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="product_template_extension_form_view" model="ir.ui.view">
+            <field name="name">product.template.extension.form.view</field>
+            <field name="model">product.template</field>
+            <field name="inherit_id" ref="product.product_template_only_form_view"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='website_sequence']" position="after">
+                    <field name="sale_on_website"/>
+                </xpath>
+            </field>
+        </record>
+    </data>
+</openerp>