У меня есть следующая проблема. Предприятие Оплата представляет виды платежей. Так что я могу например: «Кредитная карта» с оплатой в размере 2 евро, «PayPal» с комиссией в размере 1,50 евро и так далее.Symfony/PHP - объект внутри другого объекта в классе формы Тип
Тогда у меня есть лицо OrderPaymentItem, в котором хранится тип оплаты, используемый в порядке э-магазина. Зачем? Мне нужно хранить оплату за каждый заказ в электронном магазине, потому что, когда я меняю плату за платеж, она использует плату, которая была использована клиентом, когда он был завершен. Если я подключу платеж непосредственно к объекту заказа, а не к 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. Мне нужно использовать список Платежей, но сохраните его как OrderPaymentItem.
Может кто-нибудь мне помочь?
Никто не может мне помочь? –