Skip to content

Rule conditions not working #104

@flyingL123

Description

@flyingL123

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.

Activity

schmoove

schmoove commented on Sep 11, 2014

@schmoove

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

flyingL123 commented on May 5, 2015

@flyingL123
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

jarrodbell commented on Apr 28, 2016

@jarrodbell

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

PreciselyAlyss

PreciselyAlyss commented on Apr 28, 2016

@PreciselyAlyss
Contributor

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

TrevorMills commented on Dec 13, 2017

@TrevorMills

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jarrodbell@schmoove@flyingL123@TrevorMills@PreciselyAlyss

        Issue actions

          Rule conditions not working · Issue #104 · bigcommerce/bigcommerce-api-php