diff --git a/Model/Resolver/Deal.php b/Model/Resolver/Deal.php index 00bb497..f651d71 100644 --- a/Model/Resolver/Deal.php +++ b/Model/Resolver/Deal.php @@ -83,11 +83,15 @@ 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) @@ -95,6 +99,16 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value : $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; } } diff --git a/Model/Resolver/Deal/FilterArgument/EntityAttributesForAst.php b/Model/Resolver/Deal/FilterArgument/EntityAttributesForAst.php index 4f1298c..50b46ae 100644 --- a/Model/Resolver/Deal/FilterArgument/EntityAttributesForAst.php +++ b/Model/Resolver/Deal/FilterArgument/EntityAttributesForAst.php @@ -23,6 +23,7 @@ namespace Mageplaza\DailyDealGraphQl\Model\Resolver\Deal\FilterArgument; use Magento\Framework\GraphQl\Query\Resolver\Argument\FieldEntityAttributesInterface; +use Mageplaza\DailyDeal\Helper\Data; /** * Class EntityAttributesForAst @@ -30,6 +31,11 @@ */ class EntityAttributesForAst implements FieldEntityAttributesInterface { + /** + * @var Data + */ + protected $helperData; + protected $additionalAttributes = [ 'deal_id', 'product_id', @@ -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); } @@ -65,6 +75,10 @@ public function getEntityAttributes(): array $fields[$attribute] = 'String'; } + if ($this->helperData->versionCompare('2.3.4')) { + return $fields; + } + return array_keys($fields); } } diff --git a/composer.json b/composer.json index 35fad57..8bac647 100644 --- a/composer.json +++ b/composer.json @@ -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": [ { @@ -20,4 +20,4 @@ "Mageplaza\\DailyDealGraphQl\\": "" } } -} +} \ No newline at end of file diff --git a/etc/schema.graphqls b/etc/schema.graphqls index f8ed3ae..fa7e3d8 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -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 {