phpclassic / php-shopify

PHP SDK for Shopify API
Apache License 2.0
568 stars 211 forks source link

DiscountCode resource #265

Open BeerBelly opened 1 year ago

BeerBelly commented 1 year ago

Hi,

I'm trying to figure out what's the correct way of adding a discount code for a known Price Rule? Something like this doesn't work...

` $updateInfo = array( "code" => $code );

$response = $shopify->DiscountCode(PRICE_RULE_ID)->post($updateInfo);

`

Thanks for the help!

nVuln commented 1 year ago

DiscountCode is child resource of PriceRule, it's should be

$updateInfo = array(
    "code" => $code
);

$response = $shopify->PriceRule(PRICE_RULE_ID)->DiscountCode->post($updateInfo);
brianruff commented 1 year ago

It looks like Shopify is getting away from using Price Rules.

There's a note on this page about it. Does anybody know why the php-shopify is crashing with you added "write_discounts, read_discounts" scope?

https://shopify.dev/api/admin-rest/2023-01/resources/discountcode

We recommend using the GraphQL Admin API to manage discounts. The Discount types available in the GraphQL Admin API are intended to replace the GraphQL Admin PriceRule object and REST Admin PriceRule and DiscountCode resources.