public function parse() { $count = (string) $this->data; $warehouse = \Ecommerce\Warehouse::get(['name', 'Общий склад 1с']); if (!$warehouse) { $warehouse = new \Ecommerce\Warehouse(); $warehouse->name = 'Общий склад 1с'; $warehouse->save(); } $modelName = get_class($this->object->model); $warehouseOffer = \Ecommerce\Item\Offer\Warehouse::get([[$modelName::index(), $this->object->model->pk()], [\Ecommerce\Warehouse::index(), $warehouse->id]]); if (!$warehouseOffer) { $warehouseOffer = new \Ecommerce\Item\Offer\Warehouse([$modelName::index() => $this->object->model->pk(), \Ecommerce\Warehouse::index() => $warehouse->id, 'count' => $count]); } else { $warehouseOffer->count = $count; } $warehouseOffer->save(); }
public function parse() { if (is_array($this->data) && empty($this->data['@attributes'])) { foreach ($this->data as $warehouseCount) { $count = $warehouseCount['@attributes']['КоличествоНаСкладе']; $objectId = \App::$cur->migrations->findObject((string) $warehouseCount['@attributes']['ИдСклада'], 'Ecommerce\\Warehouse'); if ($objectId) { $modelName = get_class($this->model); $warehouse = \Ecommerce\Item\Offer\Warehouse::get([[$modelName::index(), $this->model->pk()], [\Ecommerce\Warehouse::index(), $objectId->object_id]]); if (!$warehouse) { $warehouse = new \Ecommerce\Item\Offer\Warehouse([$modelName::index() => $this->model->pk(), \Ecommerce\Warehouse::index() => $objectId->object_id, 'count' => $count]); $warehouse->save(); } else { if ($warehouse->count != $count) { $warehouse->count = $count; $warehouse->save(); } } } } } }