Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
  • Loading branch information
JackerNgo committed Aug 31, 2020
2 parents fd7c07b + 7ce8111 commit a3c3988
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
16 changes: 15 additions & 1 deletion Model/Resolver/Deal.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,32 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
/** @var Product $product */
$product = $value['model'];
$productId = $product->getId();
if (!$this->helperData->checkStatusDeal($productId)) {
return null;
}

/** @var \Mageplaza\DailyDeal\Model\Deal $dealData */
$dealData = $this->helperData->getProductDeal($productId);

if (!$dealData->getId()) {
return [];
return null;
}

$percent = $this->helperData->checkDealConfigurableProduct($productId)
? $this->block->getMaxPercent($productId)
: $this->block->getPercentDiscount($productId);
$dealData->setDiscountLabel($this->block->getLabel($percent));

$currentDate = $this->helperData->getCurrentDateTime();
$currentTime = strtotime($currentDate);
$fromDate = $dealData->getDateFrom();
$toDate = $dealData->getDateTo();
$remainTime = 0;
if (strtotime($toDate) >= $currentTime && strtotime($fromDate) <= $currentTime) {
$remainTime = (strtotime($toDate) - $currentTime) * 1000;
}
$dealData->setData('remaining_time', $remainTime);

return $dealData;
}
}
18 changes: 16 additions & 2 deletions Model/Resolver/Deal/FilterArgument/EntityAttributesForAst.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@
namespace Mageplaza\DailyDealGraphQl\Model\Resolver\Deal\FilterArgument;

use Magento\Framework\GraphQl\Query\Resolver\Argument\FieldEntityAttributesInterface;
use Mageplaza\DailyDeal\Helper\Data;

/**
* Class EntityAttributesForAst
* @package Mageplaza\DailyDealGraphQl\Model\Resolver\Deal\FilterArgument
*/
class EntityAttributesForAst implements FieldEntityAttributesInterface
{
/**
* @var Data
*/
protected $helperData;

protected $additionalAttributes = [
'deal_id',
'product_id',
Expand All @@ -48,10 +54,14 @@ class EntityAttributesForAst implements FieldEntityAttributesInterface
/**
* EntityAttributesForAst constructor.
*
* @param Data $helperData
* @param array $additionalAttributes
*/
public function __construct(array $additionalAttributes = [])
{
public function __construct(
Data $helperData,
array $additionalAttributes = []
) {
$this->helperData = $helperData;
$this->additionalAttributes = array_merge($this->additionalAttributes, $additionalAttributes);
}

Expand All @@ -65,6 +75,10 @@ public function getEntityAttributes(): array
$fields[$attribute] = 'String';
}

if ($this->helperData->versionCompare('2.3.4')) {
return $fields;
}

return array_keys($fields);
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mageplaza/module-daily-deal-graphql",
"description": "Magento 2 Daily Deal GraphQl Extension ",
"type": "magento2-module",
"version": "1.0.0",
"version": "1.0.1",
"license": "proprietary",
"authors": [
{
Expand All @@ -20,4 +20,4 @@
"Mageplaza\\DailyDealGraphQl\\": ""
}
}
}
}
1 change: 1 addition & 0 deletions etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type MageplazaDailyDeals {
created_at: String @doc(description: "Creation date of the deal")
updated_at: String @doc(description: "Last modification date of the deal")
discount_label: String @doc(description: "Discount Label")
remaining_time: String @doc(description: "Remaining Time")
}

interface ProductInterface {
Expand Down

0 comments on commit a3c3988

Please sign in to comment.