Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule conditions not working #104

Open
flyingL123 opened this issue Jun 24, 2014 · 5 comments
Open

Rule conditions not working #104

flyingL123 opened this issue Jun 24, 2014 · 5 comments

Comments

@flyingL123
Copy link

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.

@schmoove
Copy link

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

@flyingL123
Copy link
Author

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

@jarrodbell
Copy link

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

@PreciselyAlyss
Copy link
Contributor

PreciselyAlyss commented Apr 28, 2016

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.

@TrevorMills
Copy link

TrevorMills commented Dec 13, 2017

For anyone else coming across this issue, which still exists, even though there are a couple of pull requests for it ( #213 & #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 ) ) );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants