bigcommerce-api-php icon indicating copy to clipboard operation
bigcommerce-api-php copied to clipboard

Rule conditions not working

Open flyingL123 opened this issue 11 years ago • 5 comments

I don't think that the conditions() function is needed anymore with the Rules resource. This is because the conditions are now returned as an array on the rule object. However, currently if you try to retrieve these conditions from a rule, it breaks because this method is in the code.

Commenting out lines 1125-1132 in the bigcommerce.php file fixes the problem, so I'm thinking this means that method should be removed.

flyingL123 avatar Jun 24 '14 02:06 flyingL123

Thanks for raising this- exactly the problem I've been having. Unfortunately it looks like this library hasn't been updated in a while.

schmoove avatar Sep 11 '14 02:09 schmoove

The same is true for Sku conditions. To summarize, the conditions() method should no longer exist in the Sku and Rule resource files.

flyingL123 avatar May 05 '15 19:05 flyingL123

Can this please be fixed? It's as simple as @flyingL123 suggests - remove the conditions() methods.

jarrodbell avatar Apr 28 '16 05:04 jarrodbell

Hey all,

We appreciate the feedback on our clients and our looking to make improvements. In the meantime, we welcome anyone that wishes to open their own pull request to improve the clients.

PreciselyAlyss avatar Apr 28 '16 17:04 PreciselyAlyss

For anyone else coming across this issue, which still exists, even though there are a couple of pull requests for it ( https://github.com/bigcommerce/bigcommerce-api-php/pull/213 & https://github.com/bigcommerce/bigcommerce-api-php/pull/167 ), if you want to work around it without editing the library itself, you can add the following code to sort of cast the Rule object into a Resource object, at which point, you can access $rule->conditions to get the underlying array.

I'm leaving my own comments here so you understand this is cowboy code:

// Kludge alert.  When $rule is a Bigcommerce\Api\Resources\Rule, then $rule->conditions hits the
// conditions() method of that class, which tries to treat the conditions as a resource.  They're not
// a resource, they are an array.  Since the underlying ->fields property is protected, there's no way
// to get at that array if it's a Rule object.  So, this next line ostensibly casts it as a Resource
// object, which does not contain the conditions() method, so I can access the $rule->conditions property
// as I want to.  This is a known bug in PHP client library for the API.  See:
//   * https://github.com/bigcommerce/bigcommerce-api-php/issues/104
//   * https://github.com/bigcommerce/bigcommerce-api-php/pull/213
// Alas, for my kludgy workaround.
$rule = unserialize( str_replace( 'O:30:"Bigcommerce\Api\Resources\Rule"', 'O:24:"Bigcommerce\Api\Resource"', serialize( $rule ) ) );

TrevorMills avatar Dec 13 '17 17:12 TrevorMills