Skip to content

Commit 4970423

Browse files
committed
Initial version
1 parent 1dabc0c commit 4970423

File tree

17 files changed

+479
-2
lines changed

17 files changed

+479
-2
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea
2+
/vendor
3+
/composer.lock
4+
/tests/phpunit.xml
5+
.phpunit.result.cache

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
### Added
9+
### Changed
10+
### Removed
11+
### Fixed

CONTRIBUTING.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Contributing to IntegerNet_ProductSaleAttribute
2+
We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:
3+
4+
- Reporting a bug
5+
- Discussing the current state of the code
6+
- Submitting a fix
7+
- Proposing sale features
8+
- Becoming a maintainer
9+
10+
## We Develop with Github
11+
We use github to host code, to track issues and feature requests, as well as accept pull requests.
12+
13+
## We Use [Github Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests
14+
Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests:
15+
16+
1. Fork the repo and create your branch from `master`.
17+
2. If you've added code that should be tested, add tests.
18+
3. If you've changed APIs, update the documentation.
19+
4. Ensure the test suite passes.
20+
5. Make sure your code lints.
21+
6. Issue that pull request!
22+
23+
## Any contributions you make will be under the MIT Software License
24+
In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.
25+
26+
## Report bugs using Github's [issues](https://github.com/integer-net/magento2-product-is-sale-attribute/issues)
27+
We use GitHub issues to track public bugs. Report a bug by [opening a sale issue](https://github.com/integer-net/magento2-product-is-sale-attribute/issues/sale); it's that easy!
28+
29+
## Write bug reports with detail, background, and sample code
30+
[This is an example](http://stackoverflow.com/q/12488905/180626) of a bug report I wrote, and I think it's not a bad model. Here's [another example from Craig Hockenberry](http://www.openradar.me/11905408), an app developer whom I greatly respect.
31+
32+
**Great Bug Reports** tend to have:
33+
34+
- A quick summary and/or background
35+
- Steps to reproduce
36+
- Be specific!
37+
- Give sample code if you can. [My stackoverflow question](http://stackoverflow.com/q/12488905/180626) includes sample code that *anyone* with a base R setup can run to reproduce what I was seeing
38+
- What you expected would happen
39+
- What actually happens
40+
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
41+
42+
People *love* thorough bug reports. I'm not even kidding.
43+
44+
## Pull Requests
45+
46+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - Check the code style with ``$ composer check-style`` and fix it with ``$ composer fix-style``.
47+
48+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
49+
50+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
51+
52+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
53+
54+
- **Create feature branches** - Don't ask us to pull from your master branch.
55+
56+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
57+
58+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
59+
60+
## License
61+
By contributing, you agree that your contributions will be licensed under its MIT License.
62+
63+
## References
64+
This document was adapted from the open-source contribution guidelines for [Facebook's Draft](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md) with additions from [ThePhpLeague Template](https://github.com/thephpleague/skeleton)

README.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,62 @@
1-
# magento2-product-sale-attribute-
2-
Create an "is_sale" product attribute and update it automatically from the "price" and "special_price" attributes
1+
# IntegerNet_ProductSaleAttribute Magento Module
2+
<div align="center">
3+
4+
[![Latest Version on Packagist][ico-version]][link-packagist]
5+
[![Software License][ico-license]](LICENSE.md)
6+
![Supported Magento Versions][ico-compatibility]
7+
</div>
8+
9+
---
10+
11+
Create an "is_sale" product attribute and update it automatically from the price attributes
12+
13+
## Installation
14+
15+
1. Install it into your Magento 2 project with composer:
16+
```
17+
composer require integer-net/magento2-product-is-sale-attribute
18+
```
19+
20+
2. Enable module
21+
```
22+
bin/magento setup:upgrade
23+
```
24+
25+
## Configuration
26+
27+
You can disable auto generation in `Store -> Configuration -> Catalog -> Product "Is Sale" Attribute -> Will be updated automatically every night` per Store View.
28+
29+
## Usage
30+
31+
A sale product attribute "Is Sale" (`is_sale`) will be created upon installation of this module.
32+
A cronjob is running every night at 00:01 and regenerates the value of this attribute for each
33+
product, depending on the content of the price attributes (`price` and `special_price`) .
34+
35+
## Changelog
36+
37+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
38+
39+
## Contributing
40+
41+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
42+
43+
## Security
44+
45+
If you discover any security related issues, please email avs@integer-net.de instead of using the issue tracker.
46+
47+
## Credits
48+
49+
- [Andreas von Studnitz][link-author]
50+
- [All Contributors][link-contributors]
51+
52+
## License
53+
54+
The MIT License (MIT). Please see [License File](LICENSE) for more information.
55+
56+
[ico-version]: https://img.shields.io/packagist/v/integer-net/magento2-product-is-sale-attribute.svg?style=flat-square
57+
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
58+
[ico-compatibility]: https://img.shields.io/badge/magento-2.3%20|%202.4-brightgreen.svg?logo=magento&longCache=true&style=flat-square
59+
60+
[link-packagist]: https://packagist.org/packages/integer-net/magento2-product-is-sale-attribute
61+
[link-author]: https://github.com/avstudnitz
62+
[link-contributors]: ../../contributors

composer.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "integer-net/magento2-product-sale-attribute",
3+
"description": "Create an \"is_sale\" product attribute and update it automatically from the \"price\" and \"special_price\" attributes",
4+
"type": "magento2-module",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Andreas von Studnitz",
9+
"email": "avs@integer-net.de"
10+
}
11+
],
12+
"minimum-stability": "stable",
13+
"autoload": {
14+
"files": [
15+
"registration.php"
16+
],
17+
"psr-4": {
18+
"IntegerNet\\ProductSaleAttribute\\": "src"
19+
}
20+
},
21+
"repositories": [
22+
{
23+
"type": "composer",
24+
"url": "https://repo.magento.com/"
25+
}
26+
],
27+
"require": {
28+
"php": "~7.4||~8.1",
29+
"magento/framework": "^103.0.0"
30+
},
31+
"require-dev": {
32+
"roave/security-advisories": "dev-master",
33+
"phpunit/phpunit": "^6.0|^9.0",
34+
"pds/skeleton": "^1.0",
35+
"phpro/grumphp": "^v0.21.0",
36+
"phpstan/phpstan": "^0.12.0",
37+
"squizlabs/php_codesniffer": "^3.5",
38+
"magento/magento-coding-standard": "@dev"
39+
},
40+
"scripts": {
41+
"post-install-cmd": [
42+
"vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/"
43+
],
44+
"post-update-cmd": [
45+
"vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/"
46+
]
47+
}
48+
}

grumphp.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
grumphp:
2+
tasks:
3+
composer: []
4+
phpcs: ~
5+
phpstan:
6+
configuration: phpstan.neon
7+
phpparser:
8+
visitors:
9+
no_exit_statements: ~
10+
forbidden_function_calls:
11+
blacklist:
12+
- 'var_dump'

phpcs.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<!-- Tests do not follow the same coding standards, e.g. method names do not need to be PSR-2 compatible -->
4+
<exclude-pattern>tests/</exclude-pattern>
5+
<rule ref="Magento2"/>
6+
</ruleset>

phpstan.neon

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- src
5+
- tests
6+
ignoreErrors:
7+
- '#(class|type) Magento\\TestFramework#i'
8+
- '#(class|type) Magento\\\S*Factory#i'
9+
- '#(method) Magento\\Framework\\Api\\ExtensionAttributesInterface#i'

registration.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
\Magento\Framework\Component\ComponentRegistrar::register(
4+
\Magento\Framework\Component\ComponentRegistrar::MODULE,
5+
'IntegerNet_ProductSaleAttribute',
6+
__DIR__ . '/src'
7+
);

src/Cron/UpdateSale.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace IntegerNet\ProductSaleAttribute\Cron;
5+
6+
use IntegerNet\ProductSaleAttribute\Service\ProductsUpdateService;
7+
8+
class UpdateIsSale
9+
{
10+
private ProductsUpdateService $productUpdateService;
11+
12+
public function __construct(
13+
ProductsUpdateService $productUpdateService
14+
) {
15+
$this->productUpdateService = $productUpdateService;
16+
}
17+
18+
public function execute(): void
19+
{
20+
$this->productUpdateService->updateIsSaleValues();
21+
}
22+
}

0 commit comments

Comments
 (0)