| Total Complexity | 6 | 
| Total Lines | 51 | 
| Duplicated Lines | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php | ||
| 13 | class OrderDetailFactory extends FoxyFactory | ||
| 14 | { | ||
| 15 | /** | ||
| 16 | * @var ArrayList | ||
| 17 | */ | ||
| 18 | private $order_details; | ||
| 19 | |||
| 20 | /** | ||
| 21 | * @return $this | ||
| 22 | * @throws \SilverStripe\ORM\ValidationException | ||
| 23 | */ | ||
| 24 | protected function setOrderDetails() | ||
| 25 |     { | ||
| 26 | $details = ArrayList::create(); | ||
| 27 | |||
| 28 | /** @var ArrayList $products */ | ||
| 29 | $products = $this->getTransaction()->getParsedTransactionData()->products; | ||
| 30 | |||
| 31 | /** @var ArrayData $detail */ | ||
| 32 |         foreach ($products as $detail) { | ||
| 33 | $orderDetail = OrderDetail::create(); | ||
| 34 | |||
| 35 |             foreach ($this->config()->get('order_detail_mapping') as $foxy => $ssFoxy) { | ||
| 36 |                 if ($detail->hasField($foxy)) { | ||
| 37 |                     $orderDetail->{$ssFoxy} = $detail->getField($foxy); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | $orderDetail->write(); | ||
| 42 | |||
| 43 | $orderDetail->OrderOptions()->addMany(OrderOptionFactory::create($detail)->getOrderOptions()); | ||
| 44 | |||
| 45 | $details->push($orderDetail); | ||
| 46 | } | ||
| 47 | |||
| 48 | $this->order_details = $details; | ||
| 49 | |||
| 50 | return $this; | ||
| 51 | } | ||
| 52 | |||
| 53 | /** | ||
| 54 | * @return ArrayList | ||
| 55 | * @throws \SilverStripe\ORM\ValidationException | ||
| 56 | */ | ||
| 57 | public function getOrderDetails() | ||
| 64 | } | ||
| 65 | } | ||
| 66 |