Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Import;
- use Buxus\ImportExportTool\Data\Cell;
- use Buxus\ImportExportTool\Tool\Property\BasicProperty;
- use Buxus\Page\PageInterface;
- use Buxus\PageType\Facade\PageTypesManager;
- use Buxus\PageType\PageType;
- use Buxus\Util\PageIds;
- use Buxus\Util\PageTypeID;
- use Buxus\Util\PageTypeTag;
- use Buxus\Util\PropertyID;
- use Buxus\Util\PropertyTag;
- class ParentIdProperty extends BasicProperty
- {
- public function setValue(Cell $cell, PageInterface $page)
- {
- $parentProductId = $cell->getValue();
- $productId = $cell->getSuperiorRow()->offsetGet('segment_pro_id')->getValue()['$'];
- if ($parentProductId == $productId) {
- $page->setPageTypeId(\Buxus\Util\PageTypeID::ESHOP_PRODUCT_ID());
- return $cell->getValue();
- }
- $masterProducts = \PageFactory::getByPropertyValue($parentProductId, PropertyID::GOOGLE_MERCHANT_ID_ID(), [PageTypeID::ESHOP_PRODUCT_ID()]);
- if (empty($masterProducts)) {
- $masterProduct = \PageFactory::create(PageIds::getEshopCatalog(), PageTypeID::ESHOP_PRODUCT_ID());
- $masterProduct->setPageName($parentProductId);
- $masterProduct->setValue(PropertyTag::TITLE_TAG(), $parentProductId);
- $masterProduct->setValue(PropertyTag::GOOGLE_MERCHANT_ID_TAG(), $parentProductId);
- $masterProduct->save(false);
- $masterProductId = $masterProduct->getPageId();
- } else {
- $masterProductId = current($masterProducts);
- }
- if ($page->getParentPageId() != $masterProductId) {
- $page->setParentPageId($masterProductId);
- }
- $page->setPageTypeId(\Buxus\Util\PageTypeID::ESHOP_PRODUCT_VARIANT_ID());
- return $cell->getValue();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement