Package for connecting promotion to the project.
composer require s25/promo
- 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()