s25 / promo
package for connecting promo to the project
Installs: 5 191
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.0.0
- guzzlehttp/guzzle: >=6.3.0
This package is auto-updated.
Last update: 2025-03-29 00:53:46 UTC
README
Package for connecting promotion to the project.
Install
composer require s25/promo
Usage
- 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); } }
- 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; } }
- 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; ?>
- 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()