getLocale() public method

Returns the locale of the user.
public getLocale ( ) : string
return string Users locale
Beispiel #1
0
 /**
  * @param UserInterface $user
  * @param null|string $locale
  * @param null|string $currency
  * @param bool $persistEmptyCart Define if an empty cart should be persisted
  * @param bool $updatePrices Defines if prices should be updated
  *
  * @return null|ApiOrder
  */
 public function getUserCart($user = null, $locale = null, $currency = null, $persistEmptyCart = false, $updatePrices = false)
 {
     // cart by session ID
     if (!$user) {
         // TODO: get correct locale
         $locale = 'de';
         $cartsArray = $this->findCartBySessionId();
     } else {
         // TODO: check if cart for this sessionId exists and assign it to user
         // default locale from user
         $locale = $locale ?: $user->getLocale();
         // get carts
         $cartsArray = $this->findCartsByUser($user, $locale);
     }
     // cleanup cart array: remove duplicates and expired carts
     $this->cleanupCartsArray($cartArray);
     // check if cart exists
     if ($cartsArray && count($cartsArray) > 0) {
         // multiple carts found, do a cleanup
         $cart = $cartsArray[0];
     } else {
         // user has no cart - return empty one
         $cart = $this->createEmptyCart($user, $persistEmptyCart, $locale);
     }
     // check if all products are still available
     $cartNoRemovedProducts = $this->checkProductsAvailability($cart);
     // create api entity
     $apiOrder = $this->orderFactory->createApiEntity($cart, $locale);
     if (!$cartNoRemovedProducts) {
         $apiOrder->addCartErrorCode(self::CART_STATUS_PRODUCT_REMOVED);
     }
     $this->orderManager->updateApiEntity($apiOrder, $locale);
     // check if prices have changed
     if ($apiOrder->hasChangedPrices()) {
         $apiOrder->addCartErrorCode(self::CART_STATUS_PRICE_CHANGED);
     }
     if ($updatePrices) {
         $this->updateCartPrices($apiOrder->getItems());
     }
     return $apiOrder;
 }