我想创建一步结帐,但在结帐页面我有订单审查部分的问题.当我选择付款方式时,例如"货到付款"有5美元额外,或"checkorder"有%4折扣或"信用卡付款"增加订单总额额外.在保存付款方式之前,我需要一种计算折扣的方法.有什么建议吗?
我需要一个具有学说2的代码的具体示例,它使用"多态关联".让我澄清一下自己.我有一个名为Contract的实体,合约可以有很多价格规则,这些价格规则可以是不同类别的类,并且存在于不同的表中.我想这是多态关联,或者我错了?
class contract {
private $id;
private $priceRules;
}
class discountRule implements priceRule{
function calculate() {
// calculate new price after this rule
}
}
class extraSpecialRule implements priceRule {
function calculate() {
// calculate new price after this rule
}
}
Run Code Online (Sandbox Code Playgroud)
将来可能会有新类型的价格规则,那么我如何将这些规则与主要实体相关联并将它们固定在单独的表中呢?
更新:
这是我的新代码:
contract.php
namespace Entities;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity @Table(name="contract")
*/
class Contract {
/**
*
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*
* @Column(type="integer")
*/
private $propertyId;
/**
*
* @Column(type="integer")
*/ …
Run Code Online (Sandbox Code Playgroud) doctrine domain-driven-design polymorphic-associations doctrine-orm