Technical development documentation in order to create your own nifty site with Laracart.

Changelist 25-04-2017



Laracart Changelist

Added active() method for repository classes

\Laracart::getElementItem('element-item')->active($optional_parameter) // retreive an element item by active or custom state (0 = disabled/inactive )


Change
\Laracart::getElement('element'); // returns object

Has been changted to the example below in order to also display active and inactive elements and support for repository commands such as where etc. etc.

\Laracart::getElement('element')->active($optional_parameter) // retreive an element by active or custom state (0 = disabled/inactive )


You can now get a slider by calling the \Laracart::getSlide() command
\Laracart::getSlider('slider-name')


Changelist 18-04-2017



  1. Changelist Laracart
  2. Variables have been changed in this new update, the global variables should be accessed by the \Laracart:: Class.
  3. Consisting of methods such as:
  4. \Laracart::getModel('ModelName') which returns a dynamic repository class extending the AbstractRepositoryClass
  5. Replaced $settings by \ Laracart::getSettings()
  6. \Laracart::getSettings() return the site settings
  7. You may now access your attributes with SnakeCast company_phone may also be accessed with CompanyPhone
  8. \Laracart::getSettings()->CompanyPhone
  9. To do this, all Models have been extending a BaseModel class instead of just the Eloquent Model class.
  10. You may do so by creating new Models such as.
  11. <?php
  12. // Where your model should be placed
  13. namespace App;
  14. class YourModel extends BaseModel
  15. {
  16. /**
  17. * The database table used by the model.
  18. *
  19. * @var string
  20. */
  21. protected $table = 'your-model';
  22. }
  23. $menu_items have been replaced with
  24. \Laracart::getMenu('menu_name')
  25. This will display all active menuitems
  26. You may now create Category and menu trees easly by using the command below
  27. \Laracart::getTree()
  28. For example the code below generates a full ul li a menu list with its childs
  29. \Laracart::getTree(\Laracart::getMenu('your-menu'))
  30. You may also do the same for your shop categories
  31. \Laracart::getTree(\Laracart::getModel('ShopCategory')->where('active', '=', 1)->whereNull('parent_id')->getAll());
  32. Just remember, the \Laracart::getTree() method depends on slug and name columns. So not all models are compatible yet... We are working on this!
  33. Breadcrumbs are easy to generate too!
  34. \Laracart::getBreadcrumbs($content);
  35. Products within the category blade, should be called by $products, the @each blade is now populated with $product as $product->product // this must be changed to $product due to recent changes in the filter.
  36. You may also use $product->slug which will return the category url in the product url. This is only visisble when requesting this attribute inside the category listview.
  37. You can access the mollie and Paynl payment methods by using:
  38. \Laracart::getPaymentMethods('mollie')
  39. \Laracart::getPaymentMethods('paynl')
  40. Prices should now be called through
  41. \Laracart::currency('amount');
  42. Getting popular products etc
  43. \Laracart::getFeaturedProducts()
  44. \Laracart::getSpecialOfferProducts()
  45. \Laracart::getPopularProducts()


Redirecting to ... domain


If you get a Redirecting to ... message on your screen. Please verify that your custom controllers, models, routes etc are started properly.

This might mean that one or more files starts with an whitespace <?php

Search through products or web contents


You may use the following URL as GET Form request to search through your websites contents or products.

Please note you need a Input name search in order to search for anything.
Please note 2. When shop is activated you may not want to search through your products for some reason but still want to look for content. Please add a input hidden name pages with value 1

YOUR-DOMAIN.nl/search

You may use the following URL as GET Form request to search through your websites contents or products.



Creating your own template


Basics views
Creating your own template is very easy. Laracart supports templating and offers you to use and override the existing templates.

In order to create your own template, you will have to know how the Laracart template system works in the folders below.

root_path/resources/views/default root_path/resources/views/theme

Do not change the default folder, this will be overwritten by updating Laracart. Ignore the other folders, these are system folders and these will get overwritten if you update your laracart installation!

The default folder contains the default empty laracart site and shop templates. You can only use shop if you have purchased the shop or the shop module.

The theme folder contains no files and this is the folder where you should create your own theme.

If you want to create your own site, copy the contents of the default folder and start making some changes. 

Assets
Assets such as javascript and css files should be added to the public folder.

root_path/public/yourthemename

Please do not override the system, vendor, cart, folders. Just create your own folder and store the assets in there.

A detailed documentation about how to work with Blade themes, which laracart uses can be found on the link below.

Laravel Blade Engine (Laracart 5.3.5)

Global variables


Laracart works with a variety of global variables. These variables may be used in order to create your own template.

// List of available global variables for your template

$payment_frequency // contains an array of payment_frequencies
$menu_items // depends on default-menu (you should create a menu named default-menu first)
$categories // contains a collection of available shop categories
$settings // contains site settings defined in Laracart Settings
$manufacturers // contains a collection of shop manufacturers
$suppliers // contains a collection of shop suppliers
$multilang // return 1 or null depending on multilanguage is available
$shipping_methods // contains a collection of shipping methods
$payment_methods // contains a collection of payment methods
$mollie_methods // contains a array/object of enabled mollie payment methods such as ideal etc.
$paynl_methods // contains a array/object of enabled PayNL payment methods such as ideal etc.



Routes / URL


Laracart offers developers to create their own routes. These routes should be declared in the routes folder as site_specific_routes.php

web_root/routes/site_specific_routes.php

Page and Element routes are the last thing where Laracart searches for. So in this case, you will be able and you are free to override url's.

Please read the Laravel documentation for more information about defining your own routes.

Laravel Routing 5.3 (Laracart 5.3.5)

Defining your own routes means, that you also should create your own controllers! Do not override the existing controllers. When updating Laracart all the custom controllers will be lost. It is recommended to add a Custom prefix to your custom controllers such as.CustomContactController.php or CustomClientController.php






Debug


Debugging while developing your website should be done by reading the laravel.log file.

The Laravel log file can be found below

  1. web_root/storage/logs/laravel.log

To effectively debug your application, it is recommended to use the tail command, which allows you to display errors in real-time.

  1. tail -f web_root/storage/logs/laravel.log

If you experience different errors, please refer to your apache error logs.


SSL https


Depending on how you have configured your apache or web configuration. You can also force visitors to use secure https:// .

Just add or uncomment the following lines below in your .htaccess file in your web_root folder.

  1. RewriteCond %{HTTPS} =off
  2. RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Or you can add the following to your ENV file.


APP_SECURE_URLS=false

Caching


When your host uses opcache and you experience trouble by updating your application. Please add the line below in your web_root .htaccess file.

  1. php_flag opcache.enable Off



Settings


Settings are defined inside Laracarts site settings page.

The settings variable is a global variable which can be used withing any template without instantiating the settings eloquent model. 

  1. $settings->company_name // displays the company name
  2. $settings->company_coc // display the company chamber of commerce number
  3. $settings->company_vat // displays the company vat number
  4. $settings->company_bank // displays the company bank number
  5. $settings->company_bankno // displays the company bank number
  6. $settings->company_address // displays the company address
  7. $settings->company_zipcode
  8. $settings->company_city
  9. $settings->company_lat // latitude for google maps
  10. $settings->company_lot // longitude for google maps
  11. $settings->company_email // displays the company email
  12. $settings->company_phone // displays the company phone


Menu


Adding a menu can be done by copying the following code.

Please note, that Laracart only accepts a two-level mainmenu which can be controlled within Laracart via Menu.

The code below uses the global variable $menu_items in order to display the menu.

  1. <div class="navbar-header">
  2. <a href="#header-section-4" class="navbar-brand" title="LARACART">
  3. <img src="/system/img/laracartlogo.png" alt="Laracart Logo"/>
  4. </a>
  5. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#my-navbar-collapse" aria-expanded="false">
  6. Menu <span><i class="fa fa-expand"></i></span>
  7. </button>
  8. </div>
  9. <div class="collapse navbar-collapse" id="my-navbar-collapse">
  10. <ul class="nav navbar-nav navbar-right">
  11. @each('theme::site.layouts.elements._navbar-item', $menu_items, 'menuitem')
  12. </ul>
  13. </div>

The code above display a bootstrap-ready mobile-friendly top menu. However, you are also able to use the same code or just a bit different by using the code below. This command returns a pre-configured blade.

  1. {!! \Menu::display('menu-name') !!}

Where would Laracart be if it was not customizeable. Well even the menu's are customizeable. Just add your custom menu template to the web_root/resources/views/theme/site/menu folder. By adding the you-custom-menu.blade.php file.

Blogs



  1. ## Get all blog items
  2. @if(isset($newsitems) && count($newsitems) > 0)
  3. @foreach($newsitems->take(2) as $newsitem) ## Only get last two blog items
  4. ## blog image
  5. @if(!empty($newsitem->media))
  6. <a href="{!! \Config::get('system.blogurl') !!}/{!! $newsitem->slug !!}">
  7. <img src="/content/{{ $newsitem->media}}" alt="{{ $newsitem->media_alt }}">
  8. </a>
  9. @endif
  10. {{ Date::parse( $newsitem->publication_date )->format('d F') }}
  11. ## For the Date we use Carbon translated by Jenssegers
  12. ## https://github.com/jenssegers/date
  13. <a href="{!! \Config::get('system.blogurl') !!}/{!! $newsitem->slug !!}">
  14. <h3 >{!! $newsitem->title !!}</h3>
  15. </a>
  16. {!! str_limit(strip_tags($newsitem->content),300) !!}
  17. ## Limit content to 300 characters
  18. <a href="{!! \Config::get('system.blogurl') !!}/{!! $newsitem->slug !!}">
  19. {!! trans('custom.read-more') !!}
  20. </a>
  21. @endforeach
  22. @endif


  1. <?php
  2. $newsitems = (App\Blogs::display('nieuws')->blogs() ## Get all blog-items within category 'news'
  3. ->where('active', '=', 1) ## Get only Blogs wich are set as active
  4. ->orderBy('publication_date', 'desc') ## Order by publication dat in descending order
  5. ->whereDate('publication_date', '<=', date('Y-m-d H:i:s')) ## Exclude blogs with a publication date in the future
  6. ->get()) ;
  7. ?>

Variables:

  
    title
    description // meta description for SEO
    keywords // meta keywords for SEO
    slug
    media // Imange source
    media_alt // Image alt name
    content
    active // Set active to display on website (boolean)
    enable_comment // default false
    guest_comments 
    moderate_comments
    publication_date

Blocks


Laracart Blocks maakt het mogelijk om op iedere locatie een stuk inhoud te tonen.

  1. // Show Block
  2. \Block::display('your blockname')
  3. // optionally you can also set a custom template
  4. \Block::display('your blockname', 'template name')

De Blocks template kan aangepast worden in de site.blocks.<custom blade> bestand.

Variables:
title: name as shown on the website
name: for code reference
content
active: Set block as active to be shown on the website


Elements


Calling elements is easy, getting their child items is easy too. 

  1. $element = \Element::display('example'); // returns the element model
  2. // getting element items
  3. $element->mediaitems; // returns a collection of element-items from the displayed element


Adding pagination for your element group and or item is easy.

  1. Adding slugs to your HTML page via Elements
  2. @section('breadcrumbs')
  3. @if(isset($content->ancestors_reverse) && count($content->ancestors_reverse) > 0)
  4. @foreach($content->ancestors_reverse as $anc)
  5. <li><a href="{!! $anc->full_slug !!}">{!! $anc->title !!}</a></li>
  6. @endforeach
  7. @endif
  8. <li><a href="{!! $content->full_slug !!}">{!! $content->title !!}</a></li>
  9. @stop


Available variables

  title
  subtitle
  meta_title
  meta_description // for SEO
  meta_keywords // for SEO
  meta_focus_keyword // for SEO
  content
  filename // image source
  filename_alt // image alt name

Pages



  1. $content->title // title
  2. $content->content // content
  3. $content->slug $content->subtitle $content->meta_title $content->description $content->keywords $content->created_at $content->updated_at $content->filename $content->filename_alt


Sliders



 {!! \App\Sliders::display('homepage-slider') !!}


Reviews



  1. // Get all reviews
  2. @if(count(\App\SiteReview::get()) > 0)
  3. // foreach loop is being sent to a blade wich can be found at site/pages/custtom/elements/_home_reviews_item.blade.php
  4. @each('theme::site.pages.custom.elements._home_reviews_item',\App\SiteReview::get(), 'review')

Variables:

    function : Autors position within company (for example: manager)
    name   : Authors name
    company: Company name
    active : Show this item on the website (boolean)
    file   : Image source
    email  : Autors email
    message : content
    rating: How many stars? Rate-range between 1 and 5

Shop Category


Displaying the shop category and some more features can be achieved by using the code snippets below.

  1. \ShopCategoryService::getCategory($id); // returns the shopcategory eloquent model by its ID
  2. \ShopCategoryService::getCategoryBySlug($category_slug); // returns the shopcategory eloquent model by its SLUG
  3. \ShopCategoryService::getCategories(); // does the same as calling for $categories
  4. \ShopCategoryService::getFilters($category_model_object); // returns filters which have been defined
  5. \ShopCategoryService::getProducts($category_model_object); // returns collection of products
  6. \ShopCategoryService::getFiltersByProducts($category); // returns the filters set inside the products


An example of displaying products, and routing products.
Please note, shop routes depend on how your Laracart installation is configured. You may have prefixed your Shop routes by adding /shop or not / .

  1. example.nl/category/category-name
  2. example.nl/shop/category/category-name

Shop categories are always prefixed with category.

The category blade contains the variable $products which listens to filtering and paginating products. Please refer to the example code of default to check out what is happening.

The shop category has a many relation with products. $category->products . The Shop Products contain their own attributes and relationships. These attributes can be found at the Shop Products section.

Shop Products


Social media



  1. // variables
  2. name
  3. slug // for intern reference
  4. url
  5. description
  6. filename // image source


  1. // show all media icons
  2. {!! SocialMediaService::displayAll() !!}
  3. // show a single media item
  4. {!! SocialMediaService::display('facebook') !!}


  1. @if(count($social_media) > 0)
  2. <ul>
  3. @foreach($social_media as $social)
  4. <li>
  5. <a class="social-item" href="{!! \GeneralHelper::addHttp($social->url) !!}" target="_blank">
  6. <i class="fa fa-{!! $social->name !!}"></i>
  7. </a>
  8. </li>
  9. @endforeach
  10. </ul>
  11. @endif

You can customize social icons for the website on blade: site/socialmedia/_social_media.blade.php


Opening hours



// To display the opening hours:
{!! \OpeningHours::display() !!}


Form Builder


Form Data

The Laracart service has 2 methods for accessing form data, these are:


\Laracart::getForm('form name');

and 

\Laracart::getFormData('form id');

With these method's you can get a rendered HTML form in the form of a view (The first one).

And a object with all of the data that has been submitted to the corresponding form (The second one).



Emailing

In the directory Resources -> views -> default -> site -> form-builder -> email -> custom you can place a email template you want to use for your email. The name of the template has to be equal to the form you want to use for this to work, if no custom template is present the 'master' view in the Email directory will be used


Sms Service


You can now send sms via the Laracart service. Example:

  1. Laracart::sendSms('message', 'reciever');