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

support for send_invite #90

Open
treii28 opened this issue Jun 7, 2019 · 4 comments
Open

support for send_invite #90

treii28 opened this issue Jun 7, 2019 · 4 comments

Comments

@treii28
Copy link

treii28 commented Jun 7, 2019

I added a bare-bones definition in mine:

    'SendInvite' => [

            'httpMethod'    => 'POST',
            'uri'           => 'admin/customers/{id}/send_invite.json',
            'responseModel' => 'GenericModel',
            'summary'       => 'Send an account invite to a customer',
            'data'          => ['root_key' => 'customer_invite'],
            'parameters'    => [
                'id' => [
                    'description' => 'Customer ID',
                    'location'    => 'uri',
                    'type'        => 'integer',
                    'required'    => true,
                ],
            ],
            'additionalParameters' => [
                'location' => 'json',
            ],
        ],

With nothing but the id, it sends a standard invite. Otherwise you can include additional details to customize it:

// fed with an array similar to the return value of getCustomer
function send_invite($customer) {
    global $shopifyClient;
    $command = $shopifyClient->getCommand(
        'SendInvite',
        [
            'id' => $customer['id'],
            "to" => $customer['email'],
            "from" => "[email protected]",
            "subject" => "Some subject line",
            "custom_message" => <<<EOT
<p>Hello Everyone,</p>
<p>Please join my website</p>
<p>other custom message stuffs</p>
EOT

        ]
    );

    try {
        $results = $shopifyClient->execute($command);
        return $results;
    } catch (Exception $e) {
        $message = $e->getMessage();
        return $message;
    }
}

@bakura10
Copy link
Member

bakura10 commented Jun 7, 2019

Hi !

Thanks a lot. If you're sending us a PR with this change, I would be very happy to merge this into the library!

@treii28
Copy link
Author

treii28 commented Jun 7, 2019

I wasn't sure of what reasoning you use for the parameters you include in your definitions. For a customized invite, for example, you'd probably want a minimum of a customerId (id) and customerEmail (to) fields and likely the subject and custom_message also. But since it can technically be done with just the id on the url to send the stock message, I left those to the additional parameters in my definition

@bakura10
Copy link
Member

bakura10 commented Jun 7, 2019

The rule I have adopted in that library is that you must set explicitly ONLY the parameters that are absolutely required. So, in this case, if an ID is sufficient to make the call works, then all other parameters should be set as additioalParameters as you did :). You can threfore submit this as a PR. If there are any problem I'll let you know which change needs to be done.

@treii28
Copy link
Author

treii28 commented Jun 7, 2019

that's what I figured

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

2 participants