在odoo 9中添加到购物车按钮

时间:2019-02-25 11:25:33

标签: python odoo-8 odoo-10 odoo-9 odoo-11

我正在使用odoo9,并且当我从“可以出售”中删除复选标记时,产品页面中出现了问题,“添加到购物车”按钮仍显示在网站上,我不希望这样做,我要删除的是仅使用网站上的添加到购物车按钮来标记“可以出售”,为此,我尝试编写自定义插件,但是有一个问题,我不知道这是文件名的插件代码在哪里:


我有2个文件夹型号和视图以及拖曳文件:

1- init .py:

# -*- coding: utf-8 -*-


from. import models

2- openerp .py:

# -*- coding: utf-8 -*-

{
    'name': 'Website Sale Cart Selectable',
    'version': '9.0.1.0.0',
    'summary': 'Enables to controlling button add to cart per product',
    'author': 'OdayRafeh',
    'website': 'https:Rijssolutions.nl',
    'category': 'Website',
    'depends': ['website_sale'],
    'data': [
        'views/product_view.xml',
        'views/website_sale_template.xml'
    ],
    'installable': True,
    'license': 'AGPL-3',
}

,在“模型”文件夹中,我有那些带有代码的文件:

1- init .py:

# -*- coding: utf-8 -*-


from.import product

2- product.py:

# -*- coding: utf-8 -*-


from openerp import fields, models


class ProductTemplate(osv.Model):
    _inherit = 'product.template'

    website_btn_addtocart_published = fields.boolean(
        string='Button Add To Cart',
        copy=False,
        default=True)

,并且在views文件夹中有这些文件:

1- product_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record model="ir.ui.view" id="product_template_form_view">
            <field name="name">Product Add To Cart</field>
            <field name="model">product.template</field>
            <field name="inherit_id" ref="website_sale.product_template_form_view"/>
            <field name="arch" type="xml">
                <field name="website_published" class="pull-right" widget="website_button" position="after">
                    <field name="website_btn_addtocart_published" class="pull-right" widget="website_button"/>
                </field>
            </field>
        </record>
    </data>
</openerp>

2- website_sale_template.xml:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>   
        <template id="products_add_to_cart" inherit_id="website_sale.products_add_to_cart">
            <xpath expr="//a[@class='btn btn-default btn-xs fa fa-shopping-cart a-submit']" position="attributes">
                <t t-if="product.website_btn_addtocart_published == True">
                    <a class="btn btn-default btn-xs fa fa-shopping-cart a-submit"/>
                </t>
            </xpath>
            <xpath expr="//a[@class='btn btn-default btn-xs fa fa-shopping-cart']" position="replace">
                <t t-if="product.website_btn_addtocart_published == True">
                    <a class="btn btn-default btn-xs fa fa-shopping-cart" t-att-href="keep('/shop/product/%s' % slug(product), page=(pager['page']['num'] if pager['page']['num']>1 else None))"/>
                </t>
            </xpath>
        </template>
        <template id="product" inherit_id="website_sale.product">
            <xpath expr="//a[@class='btn btn-primary btn-lg mt8 js_check_product a-submit']" position="replace">
                <t t-if="product.website_btn_addtocart_published == True">
                    <a id="add_to_cart" class="btn btn-primary btn-lg mt8 js_check_product a-submit" href="#">Add to Cart</a>
                </t>
            </xpath>
        </template>
    </data>
</openerp>

所以请帮助了解我的错在哪里,如果还有其他方法可以实现我的目标,那么我想知道。预先感谢

0 个答案:

没有答案