I have the following problem. Entity Payment represents types of payment. So I can have for example: 'Credit Card' with 2€ fee, 'PayPal' with 1.50€ fee and so on.
Then I have entity OrderPaymentItem which stores payment type used in e-shop order. Why? I need stored payment for each e-shop order because when I change fee of payment, it use fee which was used by customer when he/she was completion order ... If I connect Payment directly to Order entity instead of to OrderPaymentItem, it recalculate old orders and it is mistake. When you change fee, it should change only in new orders ... But I don't know how to correct it. First look at these two classes:
The first entity is Payment:
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
The second entity is 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
Originally I have following form builder in basket form:
$builder->add('payment', 'entity', [
'label' => 'Platba',
'class' => 'AppBundle:Payment',
'data_class' => 'AppBundle\Entity\Payment',
'property' => 'method',
'multiple' => false,
'expanded' => true
]);
You can see that these two classes are almost same. Only OrderPaymentItem contains relation to Payment - not required but good for back compatibility.
I need to correct it now and use OrderPaymentItem instead of Payment. I need to use list of Payments, but save it as OrderPaymentItem.
Can anybody help me?