-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SalesRuleLabels to StockItems (#8)
- Loading branch information
Showing
8 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: PHPStan | ||
|
||
on: ['push', 'pull_request'] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
name: analyse | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.2 | ||
extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo | ||
coverage: none | ||
|
||
- name: Install dependencies | ||
run: composer install --no-interaction | ||
|
||
- name: Analyse | ||
run: vendor/bin/phpstan analyse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
includes: | ||
- vendor/bitexpert/phpstan-magento/extension.neon | ||
parameters: | ||
paths: | ||
- . | ||
excludePaths: | ||
- vendor | ||
- Test/* | ||
level: 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Rapidez\Compadre\Model\Resolver\Quote\Data; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\SalesRule\Api\RuleRepositoryInterface; | ||
use Magento\SalesRule\Api\Data\RuleInterface; | ||
use Magento\Quote\Model\Quote\Item; | ||
use Magento\GraphQl\Model\Query\Context; | ||
|
||
class SalesRuleLabel implements ResolverInterface | ||
{ | ||
public function __construct( | ||
protected RuleRepositoryInterface $ruleRepository | ||
) | ||
{} | ||
|
||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) | ||
{ | ||
/** @var Item */ | ||
$cartItem = $value['model']; | ||
|
||
$labels = []; | ||
|
||
foreach (explode(',', (string) $cartItem->getAppliedRuleIds()) as $key=>$ruleId) { | ||
/** @var RuleInterface $rule */ | ||
$rule = $this->ruleRepository->getById((int) $ruleId); | ||
|
||
// @phpstan-ignore-next-line | ||
$store = $context->getExtensionAttributes()->getStore(); | ||
$storeId = $store->getId(); | ||
|
||
foreach($rule->getStoreLabels() as $storeLabel) { | ||
if ((int) $storeLabel->getStoreId() === (int) $storeId) { | ||
$storeLabel = $storeLabel->getStoreLabel(); | ||
break; | ||
} | ||
} | ||
|
||
$labels[] = [ | ||
'name' => $rule->getName(), | ||
'description' => $rule->getDescription(), | ||
'discount_amount' => $rule->getDiscountAmount(), | ||
'from_date' => $rule->getFromDate(), | ||
'to_date' => $rule->getToDate(), | ||
'store_label' => $storeLabel ?? null, | ||
]; | ||
} | ||
|
||
return $labels; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters