s25 / promo
将促销连接到项目的包
1.0.1
2022-09-01 08:45 UTC
Requires
- php: >=8.0.0
- guzzlehttp/guzzle: >=6.3.0
This package is auto-updated.
Last update: 2024-09-29 06:03:23 UTC
README
将促销连接到项目的包。
安装
composer require s25/promo
用法
- 创建从基类扩展的PromotionClient
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); } }
- 创建促销客户端外观
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; } }
- 创建模板
<?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()