public static function createFromXMLResponse(\SimpleXMLElement $response) { $self = new self(); $catalog = $response->attributes()->PriceListCode ? (string) $response->attributes()->PriceListCode : null; if (is_null($catalog)) { throw new \InvalidArgumentException('Invalid Catalog received from ERP system'); } $self->setCatalog($catalog); $products = []; foreach ($response->Category->Product as $product) { $products[] = ErpProductEntity::createFromCatalogXmlResponse($product); } if (empty($products)) { throw new \InvalidArgumentException('No products to import'); } $self->setProducts($products); return $self; }