fix: Cart Logic of Item variant without Website Item
This commit is contained in:
parent
f2fbe9049f
commit
47c8ad0b94
@ -41,7 +41,7 @@ def get_cart_quotation(doc=None):
|
||||
|
||||
if not doc.customer_address and addresses:
|
||||
update_cart_address("billing", addresses[0].name)
|
||||
|
||||
print("doc>>", doc, type(doc))
|
||||
return {
|
||||
"doc": decorate_quotation_doc(doc),
|
||||
"shipping_addresses": get_shipping_addresses(party),
|
||||
@ -275,10 +275,25 @@ def guess_territory():
|
||||
|
||||
def decorate_quotation_doc(doc):
|
||||
for d in doc.get("items", []):
|
||||
item_code = d.item_code
|
||||
fields = ["web_item_name", "thumbnail", "website_image", "description", "route"]
|
||||
|
||||
# Variant Item
|
||||
if not frappe.db.exists("Website Item", {"item_code": item_code}):
|
||||
variant_data = frappe.db.get_values(
|
||||
"Item",
|
||||
filters={"item_code": item_code},
|
||||
fieldname=["variant_of", "item_name"],
|
||||
as_dict=True
|
||||
)[0]
|
||||
item_code = variant_data.variant_of
|
||||
d.website_item_name = variant_data.item_name
|
||||
fields = fields[1:]
|
||||
|
||||
d.update(frappe.db.get_value(
|
||||
"Website Item",
|
||||
{"item_code": d.item_code},
|
||||
["web_item_name", "thumbnail", "website_image", "description", "route"],
|
||||
{"item_code": item_code},
|
||||
fields,
|
||||
as_dict=True)
|
||||
)
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
import frappe
|
||||
from frappe.utils import cint
|
||||
|
||||
from erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings import get_shopping_cart_settings
|
||||
from erpnext.e_commerce.variant_selector.item_variants_cache import ItemVariantsCacheManager
|
||||
from erpnext.utilities.product import get_price
|
||||
|
||||
|
||||
def get_item_codes_by_attributes(attribute_filters, template_item_code=None):
|
||||
@ -143,14 +145,13 @@ def get_next_attribute_and_values(item_code, selected_attributes):
|
||||
filtered_items_count = len(filtered_items)
|
||||
|
||||
# get product info if exact match
|
||||
from erpnext.e_commerce.shopping_cart.product_info import get_product_info_for_website
|
||||
# from erpnext.e_commerce.shopping_cart.product_info import get_product_info_for_website
|
||||
if exact_match:
|
||||
data = get_product_info_for_website(exact_match[0])
|
||||
product_info = data.product_info
|
||||
cart_settings = get_shopping_cart_settings()
|
||||
product_info = get_item_variant_price_dict(exact_match[0], cart_settings)
|
||||
|
||||
if product_info:
|
||||
product_info["allow_items_not_in_stock"] = cint(data.cart_settings.allow_items_not_in_stock)
|
||||
if not data.cart_settings.show_price:
|
||||
product_info = None
|
||||
product_info["allow_items_not_in_stock"] = cint(cart_settings.allow_items_not_in_stock)
|
||||
else:
|
||||
product_info = None
|
||||
|
||||
@ -195,3 +196,19 @@ def get_item_attributes(item_code):
|
||||
|
||||
return attributes
|
||||
|
||||
def get_item_variant_price_dict(item_code, cart_settings):
|
||||
if cart_settings.enabled and cart_settings.show_price:
|
||||
is_guest = frappe.session.user == "Guest"
|
||||
# Show Price if logged in.
|
||||
# If not logged in, check if price is hidden for guest.
|
||||
if not is_guest or not cart_settings.hide_price_for_guest:
|
||||
price = get_price(
|
||||
item_code,
|
||||
cart_settings.price_list, #TODO
|
||||
cart_settings.default_customer_group,
|
||||
cart_settings.company
|
||||
)
|
||||
return {"price": price}
|
||||
|
||||
return None
|
||||
|
||||
|
@ -214,7 +214,7 @@ class ItemConfigure {
|
||||
? `<div class="alert alert-success d-flex justify-content-between align-items-center" role="alert">
|
||||
<div><div>
|
||||
${one_item}
|
||||
${product_info && product_info.price && !$.isEmptyObject()
|
||||
${product_info && product_info.price && !$.isEmptyObject(product_info.price)
|
||||
? '(' + product_info.price.formatted_price_sales_uom + ')'
|
||||
: ''
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user