s25/promo

package for connecting promo to the project

1.0.1 2022-09-01 08:45 UTC

This package is auto-updated.

Last update: 2024-05-29 05:03:16 UTC


README

Package for connecting promotion to the project.

Install

composer require s25/promo

Usage

  1. Create the PromotionClient extended from base class
use S25\Promo;

class PromotionClient extends BasePromotionsClient {

   public function getHeaderPlace(): PromoPlace|null
   {
        return $this->getPlace('header');
   }
   
    public function getCategoryPlace(array $conditions = []): PromoPlace|null
    {
        return $this->getPlace('header', $conditions);
    }
}
  1. Create the promo client facade
use S25\Promo;

class PromotionClientFacade
{
    private static PromotionsClient|null $instance;
    private static bool $isSet = false;

    public static function getInstance(): PromotionsClient|null
    {
        if (!self::$isSet) {
            try{
                self::$isSet = true;

                $options = new PromotionsClientOptions('host', 'project', 'ru');

                self::$instance = new PromotionsClient(new \GuzzleHttp\Client(), $options);
            } catch (Exception) {
                self::$instance = null;
            }
        }

        return self::$instance;
    }
}
  1. Create template
<?php $promotionPlace = PromotionClientFacade::getInstance()?->getHeaderPlace() ?>


<?php if($promotionPlace !== null): ?>
  <div
       [data-location-name="<?= $promotionPlace->getName() ?>"
       class="<?= $promotionPlace->getClasses() ?>"
       style="<?= $promotionPlace->getStyle() ?>"
  >
    <iframe src="<?= $promotionPlace->getIframeSrc()?>"></iframe>
  </div>
<?php endif; ?>
  1. Javascript
npm i @shop25/banners-client
import { PromotionClient } from '@shop25/banners-client'
import '@shop25/banners-client/dist/style.css'

const element = document.querySelector('[my-selector]')
const location = client.createLocation('header')

location.mount(element).then(() => console.log('mounted'))

// if need destroy
location.destroy()