02 Jan

Example for a Query in a Query in Laravel

$posts = \App\Post::orderBy('postdate', 'dsc')->with('author')->with('categorys')->with('hashtags')
->with(array('comments' => function($query){
    $query->where('comments.status', 1);
}))->where('status','publish')
   ->where('postdate', '<=' , $now)
   ->paginate(10);
27 Sep

How to create a Admin Middleware in Laravel

php artisan make:middleware Admin

The Admin.php Middleware:


namespace App\Http\Middleware;

use Closure;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Auth\Factory as Auth;

class Admin
{
    /**
     * The authentication factory instance.
     *
     * @var \Illuminate\Contracts\Auth\Factory
     */
    protected $auth;

    /**
     * Create a new middleware instance.
     *
     * @param  \Illuminate\Contracts\Auth\Factory  $auth
     * @return void
     */
    public function __construct(Auth $auth)
    {
        $this->auth = $auth;
    }

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
       
        if ($this->auth->user()->isAdmin){
            return $next($request);
        } else {
            die('not admin');
        }
        

    }
}

The new Kernel.php example

protected $routeMiddleware = [
        'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'admin' => \App\Http\Middleware\Admin::class,
    ];
24 Sep

WordPress If specific Page


if ( is_page( 'about' ) || '2' == $post->post_parent ) {    
    // the page is "About", or the parent of the page is "About"
    $bannerimg = 'about.jpg';
} elseif ( is_page( 'learning' ) || '56' == $post->post_parent ) {   
    $bannerimg = 'teaching.jpg';
} elseif ( is_page( 'admissions' ) || '15' == $post->post_parent ) { 
    $bannerimg = 'admissions.jpg';
} else { 
    $bannerimg = 'home.jpg'; // just in case we are at an unclassified page, perhaps the home page
}   

11 Jul

How to define offcanvas menu on desktop and tablet in shopware

In this file

themes/Frontend/Responsive/frontend/_public/src/js/jquery.shopware-responsive.js

you can define in line 34, when the data offcanvas is active.

Also very interesting is the Shopware Grid System in that file:

 window.StateManager.init([
        {
            state: 'xs',
            enter: 0,
            exit: 29.9375   // 479px
        },
        {
            state: 's',
            enter: 30,      // 480px
            exit: 47.9375   // 767px
        },
        {
            state: 'm',
            enter: 48,      // 768px
            exit: 63.9375   // 1023px
        },
        {
            state: 'l',
            enter: 64,      // 1024px
            exit: 78.6875   // 1259px
        },
        {
            state: 'xl',
            enter: 78.75,   // 1260px
            exit: 322.5     // 5160px
        }
    ]);
10 Jul

Manipulate the AjaxSearch in Shopware to a JSON Keyword Search

 public function indexAction()
    {
        Shopware()->Plugins()->Controller()->Json()->setPadding();

        $this->View()->loadTemplate('frontend/search/ajax.tpl');

        $term = $this->Request()->getParam('sSearch');
        $term = trim(stripslashes(html_entity_decode($term)));

        
        if (!$term || strlen($term) < Shopware()->Config()->MinSearchLenght) {
            return false;
        }


        $context  = $this->get('shopware_storefront.context_service')->getShopContext();

        $criteria = $this->get('shopware_search.store_front_criteria_factory')
            ->createAjaxSearchCriteria($this->Request(), $context);


        $result = $this->get('shopware_search.product_search')->search($criteria, $context);
        
        $term = '%' . $term . '%';
        $sql= "SELECT * FROM s_search_keywords WHERE keyword LIKE '". $term . "'";

        $keywords = Shopware()->Db()->fetchAll($sql, array(1));
        
        
        if ($result->getTotalCount() > 0) {
            //$articles = $this->convertProducts($result);
            $this->View()->searchResult = $result;
            $this->View()->sSearchRequest = array("sSearch" => $term);
            //$this->View()->sSearchResults = array("sResults" => $articles, "sArticlesCount" => $result->getTotalCount());
            $this->View()->sSearchResults = $keywords;
        }
        
    
    }