Skip to content

Commit

Permalink
Improve resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Willian Keller committed Jul 26, 2018
1 parent 0dcb942 commit b87b67a
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 62 deletions.
5 changes: 0 additions & 5 deletions Api/CookieHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

interface CookieHandlerInterface
{
/**
* @var string Cookie name.
*/
const COOKIE_NAME = 'm_cookie-law-banner';

/**
* Check if cookie exists.
*
Expand Down
24 changes: 19 additions & 5 deletions Block/Banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public function _prepareLayout()
*/
public function getIsEnabled()
{
if ($this->helperData->isActive() && !$this->cookieHandler->exists())
{
if (
$this->helperData->isActive() &&
$this->cookieHandler->exists() === false
) {
return true;
}
return false;
Expand All @@ -74,7 +76,11 @@ public function getIsEnabled()
*/
public function getTitle()
{
return $this->helperData->getTitle();
$title = $this->helperData->getTitle();
if (empty($title)) {
return false;
}
return $title;
}

/**
Expand All @@ -94,7 +100,11 @@ public function getMessage()
*/
public function getInfoMessage()
{
return $this->helperData->getInfoMessage();
$info = $this->helperData->getInfoMessage();
if (empty($info)) {
return false;
}
return $info;
}

/**
Expand All @@ -104,7 +114,11 @@ public function getInfoMessage()
*/
public function getInfoLink()
{
return $this->helperData->getInfoLink();
$link = $this->helperData->getInfoLink();
if (empty($link)) {
return false;
}
return $link;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.0.4] - 2018-07-24
## [1.0.0] - 2018-07-26
### Added
- CMS module settings (Enable/Disable)
- Initial feature
10 changes: 6 additions & 4 deletions Model/CookieHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

class CookieHandler implements CookieHandlerInterface
{
/**
* @var string Cookie name.
*/
const COOKIE_NAME = 'm_cookie-law-banner';

/**
* @var \Magento\Framework\Stdlib\CookieManagerInterface
*/
Expand All @@ -36,9 +41,6 @@ public function __construct(
*/
public function exists()
{
if (empty($this->cookieManager->getCookie(self::COOKIE_NAME))) {
return false;
}
return true;
return $this->cookieManager->getCookie(self::COOKIE_NAME, false);
}
}
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
Cookie Law Banner for Magento 2
=====================

A simple way that allows the integration of a Floating Buy Button in your store;
No matter how much content it has, like, long product description or a lot of
reviews, the button follow your customers along each product page. Bringing the
product name, price and of course, the buy button.
Get your customer attention the most important action in your online store, the
purchase.
This extension allow you to setup a Cookie Law Banner to inform your customers
about the Cookie Privacy. This extension is also fully customizable, you're
able to change the title, description, link and button text. Also compatible
mobile version.

[![Packagist](https://img.shields.io/packagist/v/magestat/module-cookie-law-banner.svg)](https://packagist.org/packages/magestat/module-cookie-law-banner)

Expand Down Expand Up @@ -43,7 +41,7 @@ php bin/magento cache:clean

1. Go to **Stores** > **Configuration** > **Magestat** > **Cookie Law Banner**:
2. In **Enable Module** tab, select **Enabled** option to enable module.
3. In **Settings** tab, Fill the fields as you need.
3. In **Settings** tab, Fill the fields as you want.

## Contribution

Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<general>
<title>Cookies Control</title>
<message>We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.</message>
<text>More info</text>
<details>More info</details>
<link>/privacy-policy-cookie-restriction-mode</link>
<button>Accept</button>
</general>
Expand Down
26 changes: 20 additions & 6 deletions view/frontend/templates/banner.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,36 @@
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* Please see LICENSE.txt for the full text of the OSL 3.0 license
*
* @var $block \Magestat\CookieLawBanner\Block\CookieLawBanner
* @var $block \Magestat\CookieLawBanner\Block\Banner
*/
?>
<?php
// Instanciate block title.
$title = $block->getTitle();

// Instanciate block link.
$link = $block->getInfoLink();

// Instanciate block info message.
$info = $block->getInfoMessage();
?>
<?php if ($block->getIsEnabled()): ?>
<div id="magestat-cookie-law-banner" data-bind="scope:'magestat-cookie-law-banner'">
<div class="content-inner-container">
<div class="banner-title">
<h3><?= /* @escapeNotVerified */ $block->getTitle() ?></h3>
</div>
<?php if ($title): ?>
<div class="banner-title">
<h3><?= /* @escapeNotVerified */ $title ?></h3>
</div>
<?php endif; ?>
<div class="banner-content">
<p class="cookie-content"><?= /* @escapeNotVerified */ $block->getMessage() ?></p>
<?php if ($link && $info): ?>
<p class="more-info-content">
<a class="link" href="<?= /* @escapeNotVerified */ $block->getInfoLink() ?>">
<em><?= /* @escapeNotVerified */ $block->getInfoMessage() ?></em>
<a class="link" href="<?= /* @escapeNotVerified */ $link ?>">
<em><?= /* @escapeNotVerified */ $info ?></em>
</a>
</p>
<?php endif; ?>
</div>
<div class="banner-button">
<button class="action primary button-accept">
Expand Down
80 changes: 50 additions & 30 deletions view/frontend/web/css/source/_module.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/**
* A Magento 2 module named Magestat/CookieLawBanner
* Copyright (C) 2018 Magestat (http://magestat.com)
Expand All @@ -8,39 +9,58 @@
* Please see LICENSE.txt for the full text of the OSL 3.0 license
*/

#magestat-cookie-law-banner {
background: #fff;
bottom: 50px;
box-shadow: -2px 2px 82px -26px rgba(0, 0, 0, .5);
left: 30px;
max-width: 400px;
overflow: hidden;
position: fixed;
text-align: center;
z-index: 48;
.content-inner-container {
padding: 20px;
}
.banner-title {
h3 {
margin: 20px 0;
text-transform: uppercase;
//
// Common (Both desktop and mobile)
// _____________________________________________

& when (@media-common = true) {
#magestat-cookie-law-banner {
background: #fff;
bottom: 50px;
box-shadow: -2px 2px 82px -26px rgba(0, 0, 0, .5);
left: 30px;
max-width: 400px;
overflow: hidden;
position: fixed;
text-align: center;
z-index: 48;
.content-inner-container {
padding: 20px;
}
}
.banner-content {
p {
margin: 5px 0;
padding: 0 15px;
.banner-title {
h3 {
margin: 20px 0;
text-transform: uppercase;
}
}
.link {
text-decoration: underline;
.banner-content {
p {
margin: 5px 0;
padding: 0 15px;
}
.link {
text-decoration: underline;
}
}
}
.banner-button {
margin: 20px 10px 5px;
.button-accept {
padding: 10px 25px;
text-transform: uppercase;
.banner-button {
margin: 20px 10px 5px;
.button-accept {
padding: 10px 25px;
text-transform: uppercase;
}
}
}
}


//
// Mobile
// _____________________________________________

.media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__m) {
#magestat-cookie-law-banner {
bottom: 15px;
left: 15px;
right: 15px;
}
}
7 changes: 4 additions & 3 deletions view/frontend/web/js/view/banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ define([
var self = this;

$(self.context).on('click', self.button, function () {
$(this).closest(self.context).addClass('remove');
// Add class to hide container.
$(this).closest(self.context).fadeOut(300);
// Set cookie as accepted.
$.cookie(self.cookieName, true);
});
$.cookie(self.cookieName, 'accepted');

return self;
}
});
Expand Down

0 comments on commit b87b67a

Please sign in to comment.