private function addOffers($offers) { $offers = DataHelper::filterRecursive($offers); foreach ($offers as $key => $offer) { if (!array_key_exists('id', $offer)) { continue; } $e = $this->offers->addChild('offer'); $e->addAttribute('id', $offer['id']); if (!array_key_exists('productId', $offer) || empty($offer['productId'])) { $offer['productId'] = $offer['id']; } $e->addAttribute('productId', $offer['productId']); if (!empty($offer['quantity'])) { $e->addAttribute('quantity', (int) $offer['quantity']); } else { $e->addAttribute('quantity', 0); } if (is_array($offer['categoryId'])) { foreach ($offer['categoryId'] as $categoryId) { $e->addChild('categoryId', $categoryId); } } else { $e->addChild('categoryId', $offer['categoryId']); } if (!array_key_exists('name', $offer) || empty($offer['name'])) { $offer['name'] = 'Без названия'; } if (!array_key_exists('productName', $offer) || empty($offer['productName'])) { $offer['productName'] = $offer['name']; } unset($offer['id'], $offer['productId'], $offer['categoryId'], $offer['quantity']); array_walk($offer, array($this, 'setOffersProperties'), $e); if (array_key_exists('params', $offer) && !empty($offer['params'])) { array_walk($offer['params'], array($this, 'setOffersParams'), $e); } unset($offers[$key]); } }