magento 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +52 -13
- data/lib/magento.rb +1 -0
- data/lib/magento/sales_rule.rb +32 -0
- data/lib/magento/shared/action_condition.rb +4 -0
- data/lib/magento/shared/condition.rb +4 -0
- data/lib/magento/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cac0ea3cb60d8b0a55431e9b404ba17108ae038642e57c7908700915a109818
|
4
|
+
data.tar.gz: '098eb32b5b64f50fd1228245ec1b2f431f3512c47ec1b23c8583fc1b4cb18022'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1125477eea00eafac5824a696777dea28b88dfe3bf9c0ea1161c2c98c286cbfa2198052669d6fbdb1b2041dc3fa987d4120167b1f4708859e1283ed018585d8b
|
7
|
+
data.tar.gz: 7db7a194488212a7d5b050d2c0acc5ec5f7f573995d291435a6a5743d39cba78320ea464f1fa2493f7672f59c5775f061f1fb9899be5ddb188b3dc9868a1c80b
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
Add in your Gemfile
|
6
6
|
|
7
7
|
```rb
|
8
|
-
gem 'magento', '~> 0.
|
8
|
+
gem 'magento', '~> 0.12.0'
|
9
9
|
```
|
10
10
|
|
11
11
|
or run
|
@@ -484,14 +484,44 @@ order.cancel # or
|
|
484
484
|
Magento::Order.cancel(order_id)
|
485
485
|
```
|
486
486
|
|
487
|
-
|
487
|
+
## Generate Sales Rules and Coupons
|
488
488
|
|
489
|
-
|
489
|
+
```rb
|
490
|
+
rule = Magento::SalesRule.create(
|
491
|
+
name: 'Discount name',
|
492
|
+
website_ids: [1],
|
493
|
+
customer_group_ids: [0,1,2,3],
|
494
|
+
uses_per_customer: 1,
|
495
|
+
is_active: true,
|
496
|
+
stop_rules_processing: true,
|
497
|
+
is_advanced: false,
|
498
|
+
sort_order: 0,
|
499
|
+
discount_amount: 100,
|
500
|
+
discount_step: 1,
|
501
|
+
apply_to_shipping: true,
|
502
|
+
times_used: 0,
|
503
|
+
is_rss: true,
|
504
|
+
coupon_type: 'specific',
|
505
|
+
use_auto_generation: true,
|
506
|
+
uses_per_coupon: 1
|
507
|
+
)
|
490
508
|
|
491
|
-
|
509
|
+
rule.generate_coupon(quantity: 1, length: 10)
|
510
|
+
```
|
511
|
+
|
512
|
+
Renarate by class method
|
492
513
|
```rb
|
493
|
-
Magento::
|
514
|
+
Magento::SalesRule.generate_coupon(
|
515
|
+
couponSpec: {
|
516
|
+
rule_id: 7,
|
517
|
+
quantity: 1,
|
518
|
+
length: 10
|
519
|
+
}
|
520
|
+
)
|
494
521
|
```
|
522
|
+
see all params in:
|
523
|
+
- [Magento docs Coupon](https://magento.redoc.ly/2.3.5-admin/tag/couponsgenerate#operation/salesRuleCouponManagementV1GeneratePost)
|
524
|
+
- [Magento docs SalesRules](https://magento.redoc.ly/2.3.5-admin/tag/salesRules#operation/salesRuleRuleRepositoryV1SavePost)
|
495
525
|
|
496
526
|
### First result
|
497
527
|
```rb
|
@@ -502,6 +532,23 @@ Magento::Product.where(name_like: 'some name%').first
|
|
502
532
|
>> <Magento::Product @sku="some-sku" ...>
|
503
533
|
```
|
504
534
|
|
535
|
+
### Count result
|
536
|
+
```rb
|
537
|
+
Magento::Product.count
|
538
|
+
>> 7855
|
539
|
+
Magento::Product.where(name_like: 'some name%').count
|
540
|
+
>> 15
|
541
|
+
```
|
542
|
+
|
543
|
+
___
|
544
|
+
|
545
|
+
##TODO:
|
546
|
+
|
547
|
+
### Search products
|
548
|
+
```rb
|
549
|
+
Magento::Product.search('tshort')
|
550
|
+
```
|
551
|
+
|
505
552
|
### Last result
|
506
553
|
```rb
|
507
554
|
Magento::Product.last
|
@@ -511,12 +558,4 @@ Magento::Product.where(name_like: 'some name%').last
|
|
511
558
|
>> <Magento::Product @sku="some-sku" ...>
|
512
559
|
```
|
513
560
|
|
514
|
-
### Count result
|
515
|
-
```rb
|
516
|
-
Magento::Product.count
|
517
|
-
>> 7855
|
518
|
-
Magento::Product.where(name_like: 'some name%').count
|
519
|
-
>> 15
|
520
|
-
```
|
521
|
-
|
522
561
|
### Tests
|
data/lib/magento.rb
CHANGED
@@ -17,6 +17,7 @@ require_relative 'magento/customer'
|
|
17
17
|
require_relative 'magento/order'
|
18
18
|
require_relative 'magento/invoice'
|
19
19
|
require_relative 'magento/guest_cart'
|
20
|
+
require_relative 'magento/sales_rule'
|
20
21
|
|
21
22
|
Dir[File.expand_path('magento/shared/*.rb', __dir__)].map { |f| require f }
|
22
23
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Magento
|
2
|
+
class SalesRule < Model
|
3
|
+
self.primary_key = :rule_id
|
4
|
+
self.entity_key = :rule
|
5
|
+
self.endpoint = 'salesRules'
|
6
|
+
|
7
|
+
# Example
|
8
|
+
# rule = Magento::SalesRule.find(5)
|
9
|
+
# rule.generate_coupon(quantity: 1, length: 10)
|
10
|
+
#
|
11
|
+
# @return {String[]}
|
12
|
+
def generate_coupon(attributes)
|
13
|
+
body = { couponSpec: { rule_id: id }.merge(attributes) }
|
14
|
+
self.class.generate_coupon(body)
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
# Example
|
19
|
+
# Magento::SalesRule.generate_coupon(
|
20
|
+
# couponSpec: {
|
21
|
+
# rule_id: 5,
|
22
|
+
# quantity: 1,
|
23
|
+
# length: 10
|
24
|
+
# }
|
25
|
+
# )
|
26
|
+
# @return {String[]}
|
27
|
+
def generate_coupon(attributes)
|
28
|
+
request.post('coupons/generate', attributes).parse
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/magento/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magento
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wallas Faria
|
@@ -63,12 +63,15 @@ files:
|
|
63
63
|
- lib/magento/query.rb
|
64
64
|
- lib/magento/record_collection.rb
|
65
65
|
- lib/magento/request.rb
|
66
|
+
- lib/magento/sales_rule.rb
|
67
|
+
- lib/magento/shared/action_condition.rb
|
66
68
|
- lib/magento/shared/address.rb
|
67
69
|
- lib/magento/shared/available_regions.rb
|
68
70
|
- lib/magento/shared/billing_address.rb
|
69
71
|
- lib/magento/shared/bundle_product_option.rb
|
70
72
|
- lib/magento/shared/category_link.rb
|
71
73
|
- lib/magento/shared/comment.rb
|
74
|
+
- lib/magento/shared/condition.rb
|
72
75
|
- lib/magento/shared/configurable_product_option.rb
|
73
76
|
- lib/magento/shared/currency.rb
|
74
77
|
- lib/magento/shared/custom_attribute.rb
|