concretecms-community-store / community_store

An open, free and community developed eCommerce system for Concrete CMS
https://concretecms-community-store.github.io/community_store/
MIT License
106 stars 66 forks source link

Modal cart translations #126

Closed Remo closed 4 years ago

Remo commented 7 years ago

Translations seems to be broken in the modal. It seems like translations inside a controller called by a custom route, don't work. More about that here https://github.com/concrete5/concrete5/issues/4680

The code below fixes this, but only in a very ugly way. I'm just keeping this here to track the state of the problem. I'd love to have a better solution in the core, but right now it's simply broken.

<?php
namespace Concrete\Package\CommunityStore\Src\CommunityStore\Cart;

use Concrete\Core\Controller\Controller as RouteController;
use View;
use Illuminate\Filesystem\Filesystem;
use Concrete\Package\CommunityStore\Src\CommunityStore\Cart\Cart as StoreCart;
use Concrete\Package\CommunityStore\Src\CommunityStore\Utilities\Calculator as StoreCalculator;
use Localization;
use Session;

class CartModal extends RouteController
{
    public function getCartModal()
    {
        $prevLocale = Session::get('previous_locale');
        if ($prevLocale) {
            Localization::changeLocale($prevLocale);
        }

        $cart = StoreCart::getCart();
        $discounts = StoreCart::getDiscounts();
        $totals = StoreCalculator::getTotals();

        $total = $totals['subTotal'];

        if (Filesystem::exists(DIR_BASE.'/application/elements/cart_modal.php')) {
            View::element('cart_modal', array('cart' => $cart, 'total' => $total, 'discounts' => $discounts, 'actiondata' => $this->post()));
        } else {
            View::element('cart_modal', array('cart' => $cart, 'total' => $total, 'discounts' => $discounts, 'actiondata' => $this->post()), 'community_store');
        }
    }
}
Mesuva commented 7 years ago

This is great, I'm pretty sure that @appliculture would be very interested in this right now.