feat: Offer Display

- Added offers section in website item
- Added more roles to website item
- Fixed attachment limit issue in website item
- Created Website Offer child doctype
- Added offers listing in Item full page view
- style fixes
This commit is contained in:
marination 2021-05-08 12:10:27 +05:30
parent c69de2d7a8
commit 0a703740bb
10 changed files with 192 additions and 6 deletions

View File

@ -37,6 +37,8 @@
"display_additional_information_section",
"show_tabbed_section",
"tabs",
"offers_section",
"offers",
"section_break_6",
"ranking",
"set_meta_tags",
@ -76,6 +78,7 @@
"read_only": 1
},
{
"collapsible": 1,
"fieldname": "section_break_6",
"fieldtype": "Section Break",
"label": "Search and SEO"
@ -179,7 +182,6 @@
"read_only": 1
},
{
"fetch_from": "item_code.image",
"fieldname": "image",
"fieldtype": "Attach Image",
"hidden": 1,
@ -286,13 +288,25 @@
"fieldname": "show_tabbed_section",
"fieldtype": "Check",
"label": "Add Section with Tabs"
},
{
"collapsible": 1,
"fieldname": "offers_section",
"fieldtype": "Section Break",
"label": "Offers"
},
{
"fieldname": "offers",
"fieldtype": "Table",
"label": "Offers to Display",
"options": "Website Offer"
}
],
"has_web_view": 1,
"image_field": "image",
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-03-18 20:37:54.955364",
"modified": "2021-04-22 15:29:13.541145",
"modified_by": "Administrator",
"module": "E-commerce",
"name": "Website Item",
@ -309,6 +323,42 @@
"role": "System Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Website Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Stock User",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Stock Manager",
"share": 1,
"write": 1
}
],
"search_fields": "item_code, item_name ,item_group",

View File

@ -138,7 +138,7 @@ class WebsiteItem(WebsiteGenerator):
try:
file_doc = frappe.get_doc("File", {
"file_url": self.website_image,
"attached_to_doctype": "Item",
"attached_to_doctype": "Website Item",
"attached_to_name": self.name
})
except frappe.DoesNotExistError:
@ -161,7 +161,7 @@ class WebsiteItem(WebsiteGenerator):
file_doc = frappe.get_doc({
"doctype": "File",
"file_url": self.website_image,
"attached_to_doctype": "Item",
"attached_to_doctype": "Website Item",
"attached_to_name": self.name
}).save()

View File

@ -0,0 +1,43 @@
{
"actions": [],
"creation": "2021-04-21 13:37:14.162162",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"offer_title",
"offer_subtitle",
"offer_details"
],
"fields": [
{
"fieldname": "offer_title",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Offer Title"
},
{
"fieldname": "offer_subtitle",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Offer Subtitle"
},
{
"fieldname": "offer_details",
"fieldtype": "Text Editor",
"label": "Offer Details"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-04-21 13:56:04.660331",
"modified_by": "Administrator",
"module": "E-commerce",
"name": "Website Offer",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}

View File

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class WebsiteOffer(Document):
pass
@frappe.whitelist()
def get_offer_details(offer_id):
return frappe.db.get_value('Website Offer', {'name': offer_id}, ['offer_details'])

View File

@ -771,3 +771,11 @@ body.product-page {
margin-top: 6px;
}
}
.offer-container {
border: 1px solid var(--gray-300);
border-style: dashed;
border-radius: 4px;
padding: 6px;
font-size: 14px;
}

View File

@ -44,6 +44,33 @@
</div>
{% endif %}
<!-- Offers -->
<br>
<h3>Offers</h3>
<div class="offer-container">
{% for offer in doc.offers %}
<div class="mt-2" style="display: flex;">
<div class="mr-2" >
<svg width="24" height="24" viewBox="0 0 24 24" stroke="var(--yellow-500)" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M19 15.6213C19 15.2235 19.158 14.842 19.4393 14.5607L20.9393 13.0607C21.5251 12.4749 21.5251 11.5251 20.9393 10.9393L19.4393 9.43934C19.158 9.15804 19 8.7765 19 8.37868V6.5C19 5.67157 18.3284 5 17.5 5H15.6213C15.2235 5 14.842 4.84196 14.5607 4.56066L13.0607 3.06066C12.4749 2.47487 11.5251 2.47487 10.9393 3.06066L9.43934 4.56066C9.15804 4.84196 8.7765 5 8.37868 5H6.5C5.67157 5 5 5.67157 5 6.5V8.37868C5 8.7765 4.84196 9.15804 4.56066 9.43934L3.06066 10.9393C2.47487 11.5251 2.47487 12.4749 3.06066 13.0607L4.56066 14.5607C4.84196 14.842 5 15.2235 5 15.6213V17.5C5 18.3284 5.67157 19 6.5 19H8.37868C8.7765 19 9.15804 19.158 9.43934 19.4393L10.9393 20.9393C11.5251 21.5251 12.4749 21.5251 13.0607 20.9393L14.5607 19.4393C14.842 19.158 15.2235 19 15.6213 19H17.5C18.3284 19 19 18.3284 19 17.5V15.6213Z" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M15 9L9 15" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M10.5 9.5C10.5 10.0523 10.0523 10.5 9.5 10.5C8.94772 10.5 8.5 10.0523 8.5 9.5C8.5 8.94772 8.94772 8.5 9.5 8.5C10.0523 8.5 10.5 8.94772 10.5 9.5Z" fill="white" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M15.5 14.5C15.5 15.0523 15.0523 15.5 14.5 15.5C13.9477 15.5 13.5 15.0523 13.5 14.5C13.5 13.9477 13.9477 13.5 14.5 13.5C15.0523 13.5 15.5 13.9477 15.5 14.5Z" fill="white" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</div>
<p class="mr-1">
<strong>{{ _(offer.offer_title) }}:</strong>
{{ _(offer.offer_subtitle) }}
<a class="offer-details" href="#"
data-offer-title="{{ offer.offer_title }}" data-offer-id="{{ offer.name }}"
role="button">
{{ _("More") }}
</a>
</p>
</div>
{% endfor %}
</div>
<!-- Add to Cart / View in Cart, Contact Us -->
<div class="mt-5 mb-5">
<div style="display: flex;" class="mb-4">
@ -147,7 +174,42 @@
};
erpnext.wishlist.add_remove_from_wishlist("add", args, success_action, failure_action);
});
$('.page_content').on('click', '.offer-details', (e) => {
// Bind action on More link in Offers
const $btn = $(e.currentTarget);
$btn.prop('disabled', true);
var d = new frappe.ui.Dialog({
title: __($btn.data('offer-title')),
fields: [
{
fieldname: 'offer_details',
fieldtype: 'HTML'
},
{
fieldname: 'section_break',
fieldtype: 'Section Break'
}
]
});
frappe.call({
method: 'erpnext.e_commerce.doctype.website_offer.website_offer.get_offer_details',
args: {
offer_id: $btn.data('offer-id')
},
callback: (value) => {
d.set_value("offer_details", value.message);
d.show();
$btn.prop('disabled', false);
}
})
});
});
</script>
{% endif %}

View File

@ -2,7 +2,7 @@
<div class="col-md-7 product-details {{ width_class }}">
<!-- title -->
<h1 class="product-title" itemprop="name">
{{ item_name }}
{{ doc.web_item_name }}
</h1>
<p class="product-code">
<span>{{ _("Item Code") }}:</span>

View File

@ -1,6 +1,6 @@
{% from "erpnext/templates/includes/macros.html" import user_review, ratings_summary %}
<div class="mt-8 ratings-reviews-section" style="display: flex;">
<div class="mt-12 ratings-reviews-section" style="display: flex;">
<div class="col-md-4 order-md-1 mt-8" style="max-width: 300px;">
{{ ratings_summary(reviews, reviews_per_rating, average_rating, average_whole_rating) }}

View File

@ -43,3 +43,12 @@
</div>
{% endblock %}
{% block base_scripts %}
<!-- js should be loaded in body! -->
<script type="text/javascript" src="/assets/frappe/js/lib/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/assets/js/frappe-web.min.js"></script>
<script type="text/javascript" src="/assets/js/control.min.js"></script>
<script type="text/javascript" src="/assets/js/dialog.min.js"></script>
<script type="text/javascript" src="/assets/js/bootstrap-4-web.min.js"></script>
{% endblock %}