Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tuyennn committed Feb 28, 2020
0 parents commit bf0231d
Show file tree
Hide file tree
Showing 41 changed files with 2,905 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.buildpath
.project
.settings/
.idea/
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
dist: trusty

language: php

php:
- 7.0
- 7.1
- 7.2
- 7.3

before_install:
- composer create-project magento/magento-coding-standard --stability=dev magento-coding-standard
- cd magento-coding-standard

script:
- vendor/bin/phpcs --ignore=../magento-coding-standard/* --standard=Magento2 --extensions=php ../.
42 changes: 42 additions & 0 deletions Block/Initialize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace GhoSter\Quickview\Block;

use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Exception\NoSuchEntityException;
use GhoSter\Quickview\Model\Config as QuickViewConfig;
use Magento\Framework\View\Element\Template;

/**
* Class Initialize block init the js
*/
class Initialize extends Template
{
/** @var QuickViewConfig */
protected $config;

/**
* @param QuickViewConfig $config
* @param Context $context
* @param array $data
*/
public function __construct(
QuickViewConfig $config,
Context $context,
array $data = []
) {
$this->config = $config;
parent::__construct($context, $data);
}

/**
* @return array
* @throws NoSuchEntityException
*/
public function getConfig()
{
return [
'baseUrl' => $this->_storeManager->getStore()->getBaseUrl()
];
}
}
158 changes: 158 additions & 0 deletions Block/QuickViewButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?php

namespace GhoSter\Quickview\Block;

use Magento\Catalog\Model\Product;
use Magento\Customer\Model\Context as CustomerContext;
use Magento\Framework\App\Http\Context as HttpContext;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\View\Element\Template;
use Magento\Framework\Json\EncoderInterface;
use GhoSter\Quickview\Model\Config;

/**
* Class QuickViewButton for rendering the button
*/
class QuickViewButton extends Template implements IdentityInterface
{
/**
* Cache tag prefix
*/
const CACHE_TAG = 'ghoster_quickview';

/** @var string */
protected $_template = 'GhoSter_Quickview::button.phtml';

/** @var Product */
private $product;

/** @var HttpContext */
private $httpContext;

/** @var EncoderInterface */
private $jsonEncoder;

/** @var Config */
protected $quickViewConfig;

/** @var int */
private $storeId;

/** @var int */
private $themeId;

/**
* QuickViewButton constructor.
* @param Context $context
* @param HttpContext $httpContext
* @param EncoderInterface $jsonEncoder
* @param Config $quickViewConfig
* @param array $data
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function __construct(
Context $context,
HttpContext $httpContext,
EncoderInterface $jsonEncoder,
Config $quickViewConfig,
array $data = []
) {
parent::__construct($context, $data);
$this->httpContext = $httpContext;
$this->jsonEncoder = $jsonEncoder;
$this->quickViewConfig = $quickViewConfig;
$this->product = $data['product'] ?? null;
$this->storeId = $this->_storeManager->getStore()->getId();
$this->themeId = $this->_design->getDesignTheme()->getId();
$this->addData([
'cache_lifetime' => 86400
]);
}


/**
* @return string
*/
public function getJsonConfig()
{
$productId = $this->getProduct()->getId();

return $this->jsonEncoder->encode(
[
'position' => 'top-center',
'path' => $this->getContainerPath(),
'closeSeconds' => 5,
'mode' => 'cat',
'product' => $productId,
'margin' => 10,
'alignment' => 0
]
);
}

/**
* @return boolean|int
*/
public function isAdminArea()
{
return $this->getArea() == 'adminhtml';
}

/**
* @return array
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getCacheKeyInfo()
{
$productId = $this->getProduct()->getId();

return [
'GHOSTER_PRODUCT_QUICK_VIEW',
$this->storeId,
$this->themeId,
$this->httpContext->getValue(CustomerContext::CONTEXT_GROUP),
'template' => $this->getTemplate(),
$productId
];
}

/**
* @return array|string[]
*/
public function getIdentities()
{
return array_merge(
($this->getProduct() instanceof IdentityInterface) ? $this->getProduct()->getIdentities() : [],
[self::CACHE_TAG . '_' . $this->getProduct()->getId()]
);
}

/**
* @param Product $product
*
* @return $this
*/
public function setProduct(Product $product)
{
$this->product = $product;

return $this;
}

/**
* @return Product
*/
public function getProduct()
{
return $this->product;
}

/**
* @return mixed
*/
public function getContainerPath()
{
return $this->quickViewConfig->getContainerPath();
}
}
11 changes: 11 additions & 0 deletions Controller/Catalog/Product/View.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace GhoSter\Quickview\Controller\Catalog\Product;

use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;

class View extends \Magento\Catalog\Controller\Product\View
{

}
Loading

0 comments on commit bf0231d

Please sign in to comment.