[IMP] website_sale_slides: support payment channels in new channel homepage

Purpose of this commit is to effectively support payment channels in the
new channel homepage. Specifications

 * display a 'Buy Course' button on payment based channels;
 * redirect to eCommerce;
 * display price;

We used everything available from eCommerce and product configurator to
find a real price to display. I must say I am quite happy with it.

This commit is linked to task ID 1936153 and PR #30770.

Co-Authored-By: Aurélien Warnon <awa@odoo.com>
Co-Authored-By: Thibault Delavallee <tde@odoo.com>
This commit is contained in:
Thibault Delavallée
2019-02-15 09:58:26 +00:00
co-authored by Aurélien Warnon
parent 8f295a64f3
commit ded92c62d2
5 changed files with 62 additions and 0 deletions
+1
View File
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import controllers
from . import models
@@ -13,5 +13,6 @@
'data': [
'data/website_sale_slides_demo.xml',
'views/slide_channel_views.xml',
'views/website_slides_templates.xml',
]
}
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import slides
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import http, _
from odoo.exceptions import AccessError, UserError
from odoo.http import request
from odoo.osv import expression
from odoo.addons.website_slides.controllers.main import WebsiteSlides
class WebsiteSaleSlides(WebsiteSlides):
def _prepare_additional_channel_values(self, values, **kwargs):
values = super(WebsiteSaleSlides, self)._prepare_additional_channel_values(values, **kwargs)
channel = values['channel']
if channel.visibility == 'payment' and channel.product_id:
pricelist = request.website.get_current_pricelist()
values['product_info'] = channel.product_id.product_tmpl_id._get_combination_info(product_id=channel.product_id.id, pricelist=pricelist)
values['product_info']['currency_id'] = request.website.currency_id
return values
@@ -0,0 +1,35 @@
<?xml version="1.0" ?>
<odoo><data>
<template id='course_main' inherit_id="website_slides.course_main">
<!-- Channel main template: override button to join channel -->
<xpath expr="//div[hasclass('o_wslides_join_channel')]" position="inside">
<t t-if="not channel.is_member and channel.visibility == 'payment'">
<t t-if="channel.product_id.website_published">
<h4>
<!-- original discounted price, if any -->
<span t-att-class="'text-danger oe_default_price %s' % ('' if product_info['has_discounted_price'] else 'd-none')"
style="text-decoration: line-through; white-space: nowrap;"
t-esc="product_info['list_price']"
t-options="{'widget': 'monetary', 'display_currency': product_info['currency_id']}"/>
<!-- real price -->
<b class="oe_price" style="white-space: nowrap;"
t-esc="product_info['price']"
t-options="{'widget': 'monetary', 'display_currency': product_info['currency_id']}"/>
<span itemprop="price" style="display:none;" t-esc="product_info['price']"/>
<span itemprop="priceCurrency" style="display:none;" t-esc="product_info['currency_id'].name"/>
</h4>
<a role="button" class="col-10 btn btn-primary" t-att-href="channel.product_id.website_url">
<span class="cta-title text_small_caps">Buy Course</span>
</a>
</t>
<t t-else="">
<a role="button" class="col-10 btn btn-light" href="#">
<span class="cta-title text_small_caps">Course Not Buyable</span>
</a>
</t>
</t>
</xpath>
</template>
</data></odoo>