26.2. Cart & Checkout

简介:
		
class Cart:
    def __init__(self):
        self.products = []
    def add(self, obj):
        self.products.append(obj)
    def notify(self):
        for obj in self.products:
            obj.notify(len(self.products))
    def price(self):
        for obj in self.products:
            print(obj.price)

class Checkout():
    def __init__(self,cart):
        self.cart = cart
        self.products = self.cart.products
        self.totals = 0
        self.accounting()
    def total(self):
        print(self.totals)
        return (self.totals)
    def accounting(self):
        for obj in self.products:
            self.totals = self.totals + obj.price
    def bill(self):
        pass

class Shipping():
    def __init__(self,checkout,ship):
        self.ship = ship
        checkout.totals = checkout.totals + ship.getCost()
    def cost(self):
        print(self.ship.getCost())

class UPS():
    def __init__(self):
        self.cost = 15.2
    def getCost(self):
        return self.cost

class FedEx(Shipping):
    def __init__(self):
        self.cost = 10
    def getCost(self):
        return self.cost

class Payment():
    def __init__(self, checkout):
        pass
    def payable(self):
        pass
    def tax(self):
        pass
		
		

26.2.1. 物流配送插件设计

			
                         +-------------+     +-----------------------+
User -> Goods -> Cart -> | Delivery    |  -> | Promotions components | -> Checkout
                         +-------------+     +-----------------------+
                         | rule A      |     | Promotion rule 1      |
                         | rule B      |     | Promotion rule 2      |
                         | rule C      |     | Promotion rule 3      |
                         | rule D      |     | Promotion rule 4      |
                         | rule E      |     | Promotion rule 5      |
                         +-------------+     +-----------------------+
			
			

数据库设计

			
 +--------------+
 | shipping     |
 +--------------+
 | id           |o---+
 | name         |    |
 | ...          |    |
 +--------------+    |    +----------------------+
                     |    | shipping_rule        |
 +--------------+    |    +----------------------+
 | zone         |    |    | id                   |
 +--------------+    +--->| shipping_id          |
 | id           |o------->| zone_id              |
 | name         |         | plugin               |
 |              |         | ...                  |
 +--------------+         +----------------------+

 +--------------+
 | delivery     |
 +--------------+
 | id           |
 | user_id      |o------>
 | address_id   |o------>
 +--------------+

	





原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
|
6月前
|
编译器 开发工具 git
【Git异常】You are in ‘detached HEAD‘ state, which means that you‘re not on any branch Checkout a branch
【Git异常】You are in ‘detached HEAD‘ state, which means that you‘re not on any branch Checkout a branch
67 0
|
12天前
|
开发工具 git
避免git产生Merge branch 'foo' into 'bar'提交
避免git产生Merge branch 'foo' into 'bar'提交
15 0
|
2月前
|
Java 程序员 开发工具
|
3月前
|
开发工具 git
git cherry-pick的使用
git cherry-pick的使用
|
4月前
|
Shell 开发工具 git
git 常用命令详解(merge/rebase/cherry-pick)
git常用命令详解。 git merge将已提交的commit(自历史记录与当前分支分开以来的提交)合并到当前分支中。 rebase变基的原理 git-cherry-pick能应用(合并)已经存在的commit,即选择合并某个特定commit
|
开发工具 git
git cherry-pick
git cherry-pick
88 0
|
开发工具 git
git 之merge 分支合并
git 之merge 分支合并
88 0
|
开发工具 git C++
Git:cherry-pick应用一个分支某些现有提交,到另外一个分支
Git:cherry-pick应用一个分支某些现有提交,到另外一个分支
704 0
Git:cherry-pick应用一个分支某些现有提交,到另外一个分支
|
开发工具 git
【Git】Git 分支管理 ( 使用 git cherry-pick 命令提取提交记录应用于当前分支 | 创建新分支应用某个提交 | git cherry-pick 冲突处理 )(一)
【Git】Git 分支管理 ( 使用 git cherry-pick 命令提取提交记录应用于当前分支 | 创建新分支应用某个提交 | git cherry-pick 冲突处理 )(一)
124 0
【Git】Git 分支管理 ( 使用 git cherry-pick 命令提取提交记录应用于当前分支 | 创建新分支应用某个提交 | git cherry-pick 冲突处理 )(一)
|
开发工具 git
【Git】Git 分支管理 ( 使用 git cherry-pick 命令提取提交记录应用于当前分支 | 创建新分支应用某个提交 | git cherry-pick 冲突处理 )(二)
【Git】Git 分支管理 ( 使用 git cherry-pick 命令提取提交记录应用于当前分支 | 创建新分支应用某个提交 | git cherry-pick 冲突处理 )(二)
230 0
【Git】Git 分支管理 ( 使用 git cherry-pick 命令提取提交记录应用于当前分支 | 创建新分支应用某个提交 | git cherry-pick 冲突处理 )(二)

热门文章

最新文章