public function restoreFromDb($orderId) { Yii::app()->shoppingCart->clear(); $order = Order::model()->findByPk($orderId); if (!$order) { throw new CException("No such order"); } $items = $order->flightItems(); foreach ($items as $item) { $flightTripElement = new FlightTripElement(); $searchParams = @unserialize($item->searchParams); if ($searchParams) { $flightTripElement->fillFromSearchParams($searchParams); } $object = @unserialize($item->object); if ($object) { $flightTripElement->flightVoyage = $object; } Yii::app()->shoppingCart->put($flightTripElement); } $items = $order->hotelItems(); foreach ($items as $item) { $hotelTripElement = new HotelTripElement(); $searchParams = @unserialize($item->searchParams); if ($searchParams) { $hotelTripElement->fillFromSearchParams($searchParams); } /*$city = City::model()->findByPk($item->cityId); $hotelTripElement->city = $city; $hotelTripElement->checkIn = $item->checkIn;*/ $object = @unserialize($item->object); if ($object) { $hotelTripElement->hotel = $object; } if (false && $hotelTripElement->searchParams && $hotelTripElement->searchParams['cityFull']) { //$hotelTripElement->searchParams->cityFull = $hotelTripElement->searchParams->cityFull->getAttributes(); } Yii::app()->shoppingCart->put($hotelTripElement); } }
public function actionAdd($type, $key, $searchId = '', $searchId2 = '', $pCacheId = '') { switch ($type) { case FlightVoyage::TYPE: /** @var $flight FlightVoyage */ $flight = FlightVoyage::getFromCache($key, $searchId); $flightSearchParams = @Yii::app()->pCache->get('flightSearchParams' . $pCacheId); if ($flight) { $id = time(); //todo: add count of flightVoyageFlights Items foreach ($flight->flights as $i => $flightElement) { $item = new FlightTripElement(); $item->fillFromSearchParams($flightSearchParams, $i > 0); $item->flightVoyage = $flight; $item->groupId = $flight->getId(); $item->id = $id++; Yii::app()->shoppingCart->put($item); } } else { throw new CHttpException(404, 'Can\'t found item inside cache'); } break; case Hotel::TYPE: /** @var $hotel Hotel */ $hotel = Hotel::getFromCache($key, $searchId, $searchId2); $hotelSearchParams = @Yii::app()->pCache->get('hotelSearchParams' . $pCacheId); if ($hotel) { $item = new HotelTripElement(); $item->fillFromSearchParams($hotelSearchParams); $item->hotel = $hotel; $item->id = time(); Yii::app()->shoppingCart->put($item); } else { throw new CHttpException(404, 'Can\'t found item inside cache'); } break; } }
public function addHotelTripElement($hotel, $hotelSearchParams) { $hotelTripElement = new HotelTripElement(); $hotelTripElement->fillFromSearchParams($hotelSearchParams); Yii::import('site.common.modules.hotel.models.*'); $hotelClient = new HotelBookClient(); $hotelClient->hotelSearchDetails($hotel); $hotelTripElement->hotel = $hotel; Yii::app()->shoppingCart->put($hotelTripElement); }