public function __clone() { parent::__clone(); $this->isFinalized->set(false); $this->isPaid->set(false); $this->isCancelled->set(false); $this->dateCompleted->set(null); $this->invoiceNumber->set(null); $original = $this->originalRecord; $this->shipments = new ARSet(); $this->orderedItems = array(); if ($original->isFinalized->get()) { foreach ($original->getShipments() as $shipment) { $cloned = clone $shipment; $cloned->order->set($this); if ($this->isMultiAddress->get()) { $this->addShipment($cloned); } else { foreach ($cloned->getItems() as $item) { $this->addItem($item); } } } } else { foreach ($original->getOrderedItems() as $item) { $this->addItem(clone $item); } } if ($this->isMultiAddress->get()) { $this->save(true); foreach ($this->getShipments() as $shipment) { if ($shipment->shippingAddress->get()) { $shipment->shippingAddress->set($this->getClonedAddress($shipment->shippingAddress->get(), false)); } $shipment->save(); foreach ($shipment->getItems() as $item) { $item->shipment->set($shipment); $item->save(); } } } // addresses if ($this->billingAddress->get()) { $this->billingAddress->set($this->getClonedAddress($this->billingAddress->get(), true)); } if ($this->shippingAddress->get()) { $this->shippingAddress->set($this->getClonedAddress($this->shippingAddress->get(), false)); } $this->save(); }
public function __clone() { parent::__clone(); $original = $this->originalRecord; $this->items = array(); foreach ($original->getItems() as $item) { $this->addItem(clone $item); } }