2015-12-14 42 views
3

我遇到以下問題。實體付款代表付款的類型。所以我可以舉個例子:2歐元費用的「信用卡」,1.50歐元費用的「貝寶」等等。Symfony/PHP - Form Type中的其他實體中的實體類

然後我有實體OrderPaymentItem它存儲電子商店訂單中使用的付款類型。爲什麼?我需要爲每個電子商店訂單存儲付款,因爲當我更改付款費用時,它使用客戶完成訂單時使用的費用...如果我將付款直接連接到訂單實體而不是訂單付款商品,它重新計算舊訂單,這是錯誤的。當您更改費用時,應該僅在新訂單中更改......但我不知道如何更正。首先來看看這兩個類:

第一個實體是付款

class Payment 
{ 
    protected $id; 
    protected $method; 
    protected $fee; 

    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 

    /** 
    * Set fee 
    * 
    * @param integer $fee 
    * @return Payment 
    */ 
    public function setFee($fee) 
    { 
     $this->fee = $fee; 

     return $this; 
    } 

    /** 
    * Get fee 
    * 
    * @return integer 
    */ 
    public function getFee() 
    { 
     return $this->fee; 
    } 

    /** 
    * Set method 
    * 
    * @param string $method 
    * @return Payment 
    */ 
    public function setMethod($method) 
    { 
     $this->method = $method; 

     return $this; 
    } 

    /** 
    * Get method 
    * 
    * @return string 
    */ 
    public function getMethod() 
    { 
     return $this->method; 
    } 
} 


AppBundle\Entity\Payment: 
    type: entity 
    table: payment 
    id: 
     id: 
      type: integer 
      generator: 
       strategy: AUTO 
    fields: 
     method: 
      column: method 
      type: string 
      nullable: false 
      unique: true 
      length: 64 
     fee: 
      column: fee 
      type: integer 
      nullable: false 

第二個實體是OrderPaymentItem

class OrderPaymentItem 
{ 
    protected $id; 
    protected $method; 
    protected $fee; 
    protected $paymentId; 

    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 

    /** 
    * Set fee 
    * 
    * @param integer $fee 
    * @return Payment 
    */ 
    public function setFee($fee) 
    { 
     $this->fee = $fee; 

     return $this; 
    } 

    /** 
    * Get fee 
    * 
    * @return integer 
    */ 
    public function getFee() 
    { 
     return $this->fee; 
    } 

    /** 
    * Set method 
    * 
    * @param string $method 
    * @return Payment 
    */ 
    public function setMethod($method) 
    { 
     $this->method = $method; 

     return $this; 
    } 

    /** 
    * Get method 
    * 
    * @return string 
    */ 
    public function getMethod() 
    { 
     return $this->method; 
    } 

    /** 
    * Set paymentId 
    * 
    * @param \AppBundle\Entity\Payment $paymentId 
    * @return OrderDiscountItem 
    */ 
    public function setPaymentId(\AppBundle\Entity\Payment $paymentId = null) 
    { 
     $this->paymentId = $paymentId; 

     return $this; 
    } 

    /** 
    * Get paymentId 
    * 
    * @return \AppBundle\Entity\Payment 
    */ 
    public function getPaymentId() 
    { 
     return $this->paymentId; 
    } 
} 


AppBundle\Entity\OrderPaymentItem: 
     type: entity 
     table: order_payment_item 
     id: 
      id: 
       type: integer 
       generator: 
        strategy: AUTO 
     fields: 
      method: 
       column: method 
       type: string 
       nullable: false 
       length: 64 
      fee: 
       column: fee 
       type: integer 
       nullable: false 
     manyToOne: 
      paymentId: 
       targetEntity: AppBundle\Entity\Payment 
       joinColumn: 
        name: payment_id 
        referencedColumnName: id 
        onDelete: SET NULL 
        nullable: true 

籃形式本來我有以下表單生成器:

$builder->add('payment', 'entity', [ 
       'label' => 'Platba', 
       'class' => 'AppBundle:Payment', 
       'data_class' => 'AppBundle\Entity\Payment', 
       'property' => 'method', 
       'multiple' => false, 
       'expanded' => true 
]); 

您可以看到這兩個類幾乎相同。只有OrderPaymentItem包含與支付的關係 - 不是必需的,但對後向兼容性很好。

我需要現在糾正它並使用OrderPaymentItem而不是Payment。我需要使用Payments列表,但將其另存爲OrderPaymentItem。

任何人都可以幫助我嗎?

+0

沒有人能幫助我嗎? –

回答

相關問題