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

Commit

Permalink
Merge pull request #32 from tuyennn/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tuyennn authored Oct 25, 2019
2 parents 9e08202 + 55f1591 commit b8efe0c
Show file tree
Hide file tree
Showing 16 changed files with 783 additions and 727 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ dist: trusty
language: php

php:
- 7.1
- 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,phtml,js ../.
- vendor/bin/phpcs --ignore=../magento-coding-standard/* --standard=Magento2 --extensions=php ../.
20 changes: 10 additions & 10 deletions Block/Adminhtml/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public function __construct(
parent::__construct($context, $data);
}

/**
* Check whether it is single store mode
*
* @return bool
*/
public function isSingleStoreMode()
{
return $this->_storeManager->isSingleStoreMode();
}

/**
* Prepare button and grid
*
Expand Down Expand Up @@ -106,14 +116,4 @@ protected function _getProductCreateUrl($type)
['set' => $this->_productFactory->create()->getDefaultAttributeSetId(), 'type' => $type]
);
}

/**
* Check whether it is single store mode
*
* @return bool
*/
public function isSingleStoreMode()
{
return $this->_storeManager->isSingleStoreMode();
}
}
38 changes: 19 additions & 19 deletions Block/Adminhtml/System/Config/Hashtag.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,6 @@ class Hashtag extends AbstractFieldArray
*/
protected $_activation;

/**
* Get activation options.
*
* @return Activation
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _getActivationRenderer()
{
if (!$this->_activation) {
$this->_activation = $this->getLayout()->createBlock(
Activation::class,
'',
['data' => ['is_render_to_js_template' => true]]
);
}

return $this->_activation;
}

/**
* @throws \Magento\Framework\Exception\LocalizedException
*/
Expand All @@ -59,6 +40,25 @@ protected function _prepareToRender()
$this->_addButtonLabel = __('Add More Hashtag');
}

/**
* Get activation options.
*
* @return Activation
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _getActivationRenderer()
{
if (!$this->_activation) {
$this->_activation = $this->getLayout()->createBlock(
Activation::class,
'',
['data' => ['is_render_to_js_template' => true]]
);
}

return $this->_activation;
}

/**
* Prepare existing row data object.
*
Expand Down
22 changes: 11 additions & 11 deletions Block/Adminhtml/System/Config/TestConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ public function render(AbstractElement $element)
return parent::render($element);
}

/**
* Return element html
*
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
return $this->_toHtml();
}

/**
* Return ajax url for collect button
*
Expand Down Expand Up @@ -75,4 +64,15 @@ public function getButtonHtml()

return $button->toHtml();
}

/**
* Return element html
*
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
return $this->_toHtml();
}
}
2 changes: 1 addition & 1 deletion Controller/Adminhtml/System/Config/TestConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function execute()

$responseData = [
'success' => $status,
'message' => $status ? __('Connection Success') :__('Unauthorized Instagram Account, check your user/password settings')
'message' => $status ? __('Connection Success') : __('Unauthorized Instagram Account, check your user/password settings')
];

} else {
Expand Down
116 changes: 58 additions & 58 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ class Data extends AbstractHelper
/** @var Filesystem */
protected $filesystem;

/** @var DriverFile */
private $driverFile;

/** @var FileMime */
private $fileMime;

/** @var \Magento\Framework\Image\AdapterFactory */
protected $imageFactory;

Expand All @@ -55,6 +49,12 @@ class Data extends AbstractHelper
/** @var InstagramConfig */
protected $config;

/** @var DriverFile */
private $driverFile;

/** @var FileMime */
private $fileMime;

/**
* Data constructor.
* @param Context $context
Expand Down Expand Up @@ -254,58 +254,6 @@ private function _convertWrongFormatImage(
return true;
}

/**
* Get Category Tags
*
* @param $product Product
* @return string
*/
public function getCategoriesHashtagsHtml($product)
{
$html = '';

$hashTagsStrippedData = [];

if ($this->config->isEnableCategoryHashtag() && $this->config->isEnableHashtag()) {

try {

/** @var $collection CategoryCollection */
$collection = $this->categoryCollectionFactory->create();
$collection->addAttributeToFilter('entity_id', $product->getCategoryIds());
$collection->addNameToResult();

$i = 1;
foreach ($collection as $category) {
$hashTagsStrippedData[] = strtolower(preg_replace('/\s+/', '', $category->getName()));
if ($i++ == self::DEFAULT_CATEGORY_HASHTAG_LIMIT) {
break;
}
}

} catch (\Exception $e) {
$this->_logger->error($e->getMessage());
}
}

if (!empty($hashTagsStrippedData)) {
foreach ($hashTagsStrippedData as $hashTag) {
$html .= '#' . $hashTag . self::SPACE_STRING;
}
}

return $html;
}

/**
* @param $product Product
* @return string
*/
public function getProductDescription($product)
{
return strip_tags($product->getDescription());
}

/**
* Get Final Caption for Instagram Post
*
Expand Down Expand Up @@ -371,4 +319,56 @@ public function getCustomHashHashtagsHtml($store = null)

return $html;
}

/**
* Get Category Tags
*
* @param $product Product
* @return string
*/
public function getCategoriesHashtagsHtml($product)
{
$html = '';

$hashTagsStrippedData = [];

if ($this->config->isEnableCategoryHashtag() && $this->config->isEnableHashtag()) {

try {

/** @var $collection CategoryCollection */
$collection = $this->categoryCollectionFactory->create();
$collection->addAttributeToFilter('entity_id', $product->getCategoryIds());
$collection->addNameToResult();

$i = 1;
foreach ($collection as $category) {
$hashTagsStrippedData[] = strtolower(preg_replace('/\s+/', '', $category->getName()));
if ($i++ == self::DEFAULT_CATEGORY_HASHTAG_LIMIT) {
break;
}
}

} catch (\Exception $e) {
$this->_logger->error($e->getMessage());
}
}

if (!empty($hashTagsStrippedData)) {
foreach ($hashTagsStrippedData as $hashTag) {
$html .= '#' . $hashTag . self::SPACE_STRING;
}
}

return $html;
}

/**
* @param $product Product
* @return string
*/
public function getProductDescription($product)
{
return strip_tags($product->getDescription());
}
}
35 changes: 24 additions & 11 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function isEnabled($store = null)
return false;
}

return (bool)$this->scopeConfig->getValue(
return $this->scopeConfig->isSetFlag(
static::XML_PATH_ENABLED_MODULE,
ScopeInterface::SCOPE_STORE,
$store
Expand Down Expand Up @@ -210,11 +210,11 @@ public function isObserverEnabled($store = null)
* Check if Hashtag was enabled
*
* @param null $store
* @return mixed
* @return bool
*/
public function isEnableHashtag($store = null)
{
return (bool)$this->scopeConfig->getValue(
return $this->scopeConfig->isSetFlag(
self::XML_PATH_COMMENT_ENABLED,
ScopeInterface::SCOPE_STORE,
$store
Expand All @@ -224,11 +224,11 @@ public function isEnableHashtag($store = null)
/**
* Check if Hashtag follows Parent Category
* @param null $store
* @return mixed
* @return bool
*/
public function isEnableCategoryHashtag($store = null)
{
return (bool)$this->scopeConfig->getValue(
return $this->scopeConfig->isSetFlag(
self::XML_PATH_COMMENT_CATEGORY_HASHTAG,
ScopeInterface::SCOPE_STORE,
$store
Expand All @@ -239,11 +239,11 @@ public function isEnableCategoryHashtag($store = null)
* Check if Custom Hashtag was enabled
*
* @param null $store
* @return mixed
* @return bool
*/
public function isEnableCustomHashtag($store = null)
{
return (bool)$this->scopeConfig->getValue(
return $this->scopeConfig->isSetFlag(
self::XML_PATH_COMMENT_CUSTOM_HASHTAG_ENABLED,
ScopeInterface::SCOPE_STORE,
$store
Expand All @@ -254,11 +254,11 @@ public function isEnableCustomHashtag($store = null)
* Check if Caption included Product Desc
*
* @param null $store
* @return mixed
* @return bool
*/
public function isEnableProductDescription($store = null)
{
return (bool)$this->scopeConfig->getValue(
return $this->scopeConfig->isSetFlag(
self::XML_PATH_COMMENT_PRODUCT_DESCRIPTION,
ScopeInterface::SCOPE_STORE,
$store
Expand Down Expand Up @@ -309,15 +309,22 @@ public function getInstagramPostTemplate($store = null)
));
}

/**
* @param null $store
* @return bool
*/
public function isCronEnabled($store = null)
{
return (bool)($this->scopeConfig->getValue(
return $this->scopeConfig->isSetFlag(
self::XML_PATH_CRON_ENABLED,
ScopeInterface::SCOPE_STORE,
$store
));
);
}

/**
* @return mixed
*/
public function getCronTime()
{
return $this->scopeConfig->getValue(
Expand All @@ -326,6 +333,9 @@ public function getCronTime()
);
}

/**
* @return mixed
*/
public function getCronFreq()
{
return $this->scopeConfig->getValue(
Expand All @@ -334,6 +344,9 @@ public function getCronFreq()
);
}

/**
* @return mixed
*/
public function getCronLimit()
{
return $this->scopeConfig->getValue(
Expand Down
Loading

0 comments on commit b8efe0c

Please sign in to comment.