Download the PHP package breadhead/mailchimp-ecommerce-event-pusher without Composer

On this page you can find all versions of the php package breadhead/mailchimp-ecommerce-event-pusher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mailchimp-ecommerce-event-pusher

mailchimp-event-pusher

Send events to mailchimp ecommerce

do migrations:

php yii migrate --migrationPath=@vendor/breadhead/yii2-mailchimp-ecommerce-event-pusher/src/migrations/

Implement your model class from MailchimpEventInterface. This ecommerce module for tracking:

Example of realization:

public function saveMailchimpEvent(string $event_type): MailchimpEvent
    {
        $event = (new MailchimpEvent())->setEntityId($this->id)->setEntityType(MailchimpEvent::CUSTOMER)->setEventType($event_type)->setData($this->getMailchimpData())->save();

        return $event;
    }

public function getMailchimpData()
{
    return [
        'id' => (string)$this->id,
        "email_address" =>(string)$this->email,
        'opt_in_status' => (bool)$this->subscribe,
        'first_name' => (string)$this->name,
        'last_name' => (string)$this->last_name,
        'orders_count' => count($this->orders),
        'total_spent' => (float)OrderModel::find()->where(['status' => OrderModel::PAYED, 'customer_id' => $this->id])->sum('total')
    ];
}

config:

'components' => [
    'mailchimpeventpusher' => function () {
        $storeId = <Your mailchimp store id>;
        $mailchimpApiKey = <Your mailchimp api key>;
        $listId = <Your mailchimp list id>;

        $client = new \breadhead\mailchimp\api\MailchimpClient($mailchimpApiKey);
        $sender = new \breadhead\mailchimp\MailchimpEventSender($client, $storeId, $listId);

        return new \breadhead\mailchimp\MailchimpEventPusher($storeId, $sender);
    }
]

To send events code example:

class MailchimpController extends Controller
{
    private $maxEventsPerStep;

    ...

    public function actionSendevents(): void
    {
        $jobs = $this->defineJobs();

        $this->doJobs($jobs);
    }

    private function doJobs($jobs): bool
    {
        try {
            $eventSender = \Yii::$app->mailchimpeventpusher->getManager();

            foreach ($jobs as $event) {
                $event->status = MailchimpEventModel::RUN;
                Helper::saveAndLogModel($event);

                $mailchimpEvent = MailchimpEvent::create($event->id);

                /* @var MailchimpEventSender $eventSender */
                $eventSender->sendEvent($mailchimpEvent);
            }
        } catch (\Exception $e) {

            throw $e;
        }

        return true;
    }

    private function defineJobs(): array
    {
        if (MailchimpEventModel::findOne(['status' => MailchimpEventModel::RUN])) {
            return [];
        }

        return MailchimpEventModel::find()
            ->where(['status' => MailchimpEventModel::NEW])
            ->orderBy(['created_at' => 'ASC'])
            ->limit($this->maxEventsPerStep)
            ->all();
    }
    ...
}

Important issue that if you need to unsubscribe your customer or delete it, customer methods don't help in this case. You need to use Member as an EntityType. Check example below (from CustomerModel ActiveRecord class) for more details:

public function supportEvent(string $eventType): bool
{
    $support = YII_ENV == 'prod';

    if ($support && $eventType == ActiveRecord::EVENT_BEFORE_UPDATE && $this->subscribe <> $this->oldAttributes['subscribe']) {
        $support = true;
    }

    return $support;
}

public function createAndSaveMailchimpEvent(string $eventType): MailchimpEvent
{
    if ($this->user->status == BaseActiveRecord::DELETED && $eventType == ActiveRecord::EVENT_AFTER_UPDATE) {
        $event = MailchimpEvent::createEmpty()
            ->setEntityId(MC_PREFIX . $this->id)
            ->setEntityType(MailchimpEvent::CONCACT)
            ->setEventType(ActiveRecord::EVENT_AFTER_DELETE)
            ->setData($this->getMailchimpMemberData())
            ->save();
    } elseif ($eventType == ActiveRecord::EVENT_BEFORE_UPDATE) {
        $event = MailchimpEvent::createEmpty()
            ->setEntityId(MC_PREFIX . $this->id)
            ->setEntityType(MailchimpEvent::CONCACT)
            ->setEventType(ActiveRecord::EVENT_AFTER_UPDATE)
            ->setData($this->getMailchimpMemberData())
            ->save();
    } else {
        $event = MailchimpEvent::createEmpty()
            ->setEntityId(MC_PREFIX . $this->id)
            ->setEntityType(MailchimpEvent::CUSTOMER)
            ->setEventType($eventType)
            ->setData($this->getMailchimpData())
            ->save();
    }

    return $event;
}

public function getMailchimpData()
{
    return [
        'id'            => (string) MC_PREFIX . $this->id,
        'email_address' => (string) $this->email,
        'opt_in_status' => (bool) $this->subscribe,
        'first_name'    => (string) $this->name,
        'orders_count'  => count($this->orders),
        'total_spent'   => (float) OrderModel::find()
            ->where(['transaction.status' => OrderModel::PAYED, 'order.customer_id' => $this->id])
            ->joinWith('transaction')
            ->sum('transaction.total')
    ];
}

public function getMailchimpMemberData()
{
    return [
        'email_address' => $this->user->status == self::DELETED ? $this->name: $this->email,
        'status' => $this->subscribe ? 'subscribed' : 'unsubscribed'
    ];
}

All versions of mailchimp-ecommerce-event-pusher with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
yiisoft/yii2 Version ~2.0.14
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package breadhead/mailchimp-ecommerce-event-pusher contains the following files

Loading the files please wait ....