File manager - Edit - /home/c14075/dragmet-ural.ru/www/Barcode.tar
Back
BarcodeFactory.php 0000644 00000001730 15150023330 0010135 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Barcode; use Bitrix\Catalog\v2\IoC\ContainerContract; /** * Class BarcodeFactory * * @package Bitrix\Catalog\v2\Barcode * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ class BarcodeFactory { public const BARCODE = Barcode::class; public const BARCODE_COLLECTION = BarcodeCollection::class; protected $container; /** * StoreFactory constructor. * * @param \Bitrix\Catalog\v2\IoC\ContainerContract $container */ public function __construct(ContainerContract $container) { $this->container = $container; } /** * @return \Bitrix\Catalog\v2\Barcode\Barcode */ public function createEntity(): Barcode { return $this->container->make(self::BARCODE); } /** * @return \Bitrix\Catalog\v2\Barcode\BarcodeCollection */ public function createCollection(): BarcodeCollection { return $this->container->make(self::BARCODE_COLLECTION); } } HasBarcodeCollection.php 0000644 00000000650 15150023330 0011255 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Barcode; /** * Interface HasBarcodeCollection * * @package Bitrix\Catalog\v2\Barcode * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ interface HasBarcodeCollection { public function getBarcodeCollection(): BarcodeCollection; public function setBarcodeCollection(BarcodeCollection $barcodeCollection); } BarcodeRepositoryContract.php 0000644 00000000745 15150023330 0012410 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Barcode; use Bitrix\Catalog\v2\RepositoryContract; use Bitrix\Catalog\v2\Sku\BaseSku; /** * Interface StoreProductRepositoryContract * * @package Bitrix\Catalog\v2\StoreProduct * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ interface BarcodeRepositoryContract extends RepositoryContract { public function getCollectionByParent(BaseSku $sku): BarcodeCollection; } BarcodeCollection.php 0000644 00000002643 15150023330 0010625 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Barcode; use Bitrix\Catalog\v2\BaseCollection; use Bitrix\Catalog\v2\BaseEntity; use Bitrix\Catalog\v2\IoC\ContainerContract; use Bitrix\Catalog\v2\IoC\Dependency; /** * Class BarcodeCollection * * @package Bitrix\Catalog\v2\Barcode * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ class BarcodeCollection extends BaseCollection { /** @var ContainerContract */ protected $container; /** @var \Bitrix\Catalog\v2\StoreProduct\BarcodeFactory */ protected $factory; public function __construct(ContainerContract $container, BarcodeFactory $factory) { $this->container = $container; $this->factory = $factory; } public function create(): Barcode { $barcode = $this->factory->createEntity(); $this->add($barcode); return $barcode; } public function getItemByBarcode(string $barcode): ?Barcode { /** @var Barcode $item */ foreach ($this->items as $item) { if ($barcode === $item->getBarcode()) { return $item; } } return null; } public function setSimpleBarcodeValue(string $value = ''): self { $barcodeItem = $this->getFirst(); if ($value !== '') { if (!$barcodeItem) { $barcodeItem = $this->create(); $this->add($barcodeItem); } $barcodeItem->setBarcode($value); } elseif ($barcodeItem) { $barcodeItem->remove(); } return $this; } } Barcode.php 0000644 00000003036 15150023330 0006606 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Barcode; use Bitrix\Catalog\v2\BaseEntity; use Bitrix\Catalog\v2\Fields\TypeCasters\MapTypeCaster; use Bitrix\Catalog\v2\HasSettingsTrait; /** * Class Barcode * * @package Bitrix\Catalog\v2\Barcode * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ class Barcode extends BaseEntity { use HasSettingsTrait; public function __construct(BarcodeRepositoryContract $repository) { parent::__construct($repository); } public function setStoreId(int $storeId): self { $this->setField('STORE_ID', $storeId); return $this; } public function getStoreId(): string { return $this->getField('STORE_ID'); } public function setProductId(int $productId): self { $this->setField('PRODUCT_ID', $productId); return $this; } public function getProductId(): int { return (int)$this->getField('PRODUCT_ID'); } public function setBarcode(?string $barcode): self { $this->setField('BARCODE', $barcode); return $this; } public function unsetBarcode(): self { return $this->setBarcode(null); } public function hasBarcode(): bool { return $this->hasField('BARCODE'); } public function getBarcode(): ?string { return $this->hasBarcode() ? (string)$this->getField('BARCODE') : null; } protected function getFieldsMap(): array { return [ 'ID' => MapTypeCaster::NULLABLE_INT, 'PRODUCT_ID' => MapTypeCaster::INT, 'STORE_ID' => MapTypeCaster::INT, 'BARCODE' =>MapTypeCaster::NULLABLE_STRING, ]; } } BarcodeRepository.php 0000644 00000010405 15150023330 0010704 0 ustar 00 <?php namespace Bitrix\Catalog\v2\Barcode; use Bitrix\Catalog\v2\BaseEntity; use Bitrix\Catalog\v2\Sku\BaseSku; use Bitrix\Main\Error; use Bitrix\Main\Result; use Bitrix\Catalog; /** * Class BarcodeRepository * * @package Bitrix\Catalog\v2\Barcode * * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice. * @internal */ class BarcodeRepository implements BarcodeRepositoryContract { /** @var BarcodeFactory */ protected $factory; public function __construct(BarcodeFactory $factory) { $this->factory = $factory; } /** * @inheritDoc */ public function getEntityById(int $id): ?BaseEntity { if ($id <= 0) { throw new \OutOfRangeException($id); } $entities = $this->getEntitiesBy([ 'filter' => [ '=ID' => $id, ], ]); return reset($entities) ?: null; } /** * @inheritDoc */ public function getEntitiesBy($params): array { $entities = []; foreach ($this->getList((array)$params) as $item) { $entities[] = $this->createEntity($item); } return $entities; } public function getProductId(BaseEntity $entity): ?int { $id = null; $parent = $entity->getParent(); if ($parent && !$parent->isNew()) { $id = $parent->getId(); } return $id; } /** * @inheritDoc */ public function save(BaseEntity ...$entities): Result { $result = new Result(); /** @var Barcode $entity */ foreach ($entities as $entity) { if (!$entity->getProductId()) { $productId = $this->getProductId($entity); if ($productId) { $entity->setProductId($productId); } else { $result->addError(new Error('Wrong product id')); continue; } } if ($entityId = $entity->getId()) { $res = $this->updateInternal($entityId, $entity->getChangedFields()); if (!$res->isSuccess()) { $result->addErrors($res->getErrors()); } } else { $res = $this->addInternal($entity->getFields()); if ($res->isSuccess()) { $entity->setId($res->getData()['ID']); } else { $result->addErrors($res->getErrors()); } } } return $result; } /** * @inheritDoc */ public function delete(BaseEntity ...$entities): Result { $result = new Result(); /** @var Barcode $entity */ foreach ($entities as $entity) { if ($entityId = $entity->getId()) { $res = $this->deleteInternal($entityId); if (!$res->isSuccess()) { $result->addErrors($res->getErrors()); } } } return $result; } public function getCollectionByParent(BaseSku $sku): BarcodeCollection { if ($sku->isNew()) { return $this->createCollection(); } $result = $this->getByProductId($sku->getId()); return $this->createCollection($result); } protected function getByProductId(int $skuId): array { return $this->getList([ 'filter' => [ '=PRODUCT_ID' => $skuId, '=ORDER_ID' => null, ], ]); } protected function getList(array $params): array { $rows = Catalog\StoreBarcodeTable::getList($params)->fetchAll(); return array_column($rows, null, 'ID'); } protected function createEntity(array $fields = []): Barcode { $entity = $this->factory->createEntity(); $entity->initFields($fields); return $entity; } protected function createCollection(array $entityFields = []): BarcodeCollection { $collection = $this->factory->createCollection(); foreach ($entityFields as $fields) { $barcode = $this->createEntity($fields); $collection->add($barcode); } return $collection; } protected function addInternal(array $fields): Result { $result = new Result(); $res = Catalog\StoreBarcodeTable::add($fields); if ($res->isSuccess()) { $result->setData(['ID' => $res->getId()]); } else { $result->addErrors($res->getErrors()); } return $result; } protected function updateInternal(int $id, array $fields): Result { $result = new Result(); $res = Catalog\StoreBarcodeTable::update($id, $fields); if (!$res->isSuccess()) { $result->addErrors($res->getErrors()); } return $result; } protected function deleteInternal(int $id): Result { $result = new Result(); $res = Catalog\StoreBarcodeTable::delete($id); if (!$res->isSuccess()) { $result->addErrors($res->getErrors()); } return $result; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.25 |
proxy
|
phpinfo
|
Settings