Code Monkey home page Code Monkey logo

promo's Introduction

Description

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()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.