SHARE
TWEET

Untitled

a guest Feb 14th, 2020 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Import;
  4.  
  5. use Buxus\ImportExportTool\Data\Cell;
  6. use Buxus\ImportExportTool\Tool\Property\BasicProperty;
  7. use Buxus\Page\PageInterface;
  8. use Buxus\PageType\Facade\PageTypesManager;
  9. use Buxus\PageType\PageType;
  10. use Buxus\Util\PageIds;
  11. use Buxus\Util\PageTypeID;
  12. use Buxus\Util\PageTypeTag;
  13. use Buxus\Util\PropertyID;
  14. use Buxus\Util\PropertyTag;
  15.  
  16. class ParentIdProperty extends BasicProperty
  17. {
  18.     public function setValue(Cell $cell, PageInterface $page)
  19.     {
  20.         $parentProductId = $cell->getValue();
  21.         $productId = $cell->getSuperiorRow()->offsetGet('segment_pro_id')->getValue()['$'];
  22.  
  23.         if ($parentProductId == $productId) {
  24.             $page->setPageTypeId(\Buxus\Util\PageTypeID::ESHOP_PRODUCT_ID());
  25.             return $cell->getValue();
  26.         }
  27.  
  28.         $masterProducts = \PageFactory::getByPropertyValue($parentProductId, PropertyID::GOOGLE_MERCHANT_ID_ID(), [PageTypeID::ESHOP_PRODUCT_ID()]);
  29.  
  30.         if (empty($masterProducts)) {
  31.             $masterProduct = \PageFactory::create(PageIds::getEshopCatalog(), PageTypeID::ESHOP_PRODUCT_ID());
  32.             $masterProduct->setPageName($parentProductId);
  33.             $masterProduct->setValue(PropertyTag::TITLE_TAG(), $parentProductId);
  34.             $masterProduct->setValue(PropertyTag::GOOGLE_MERCHANT_ID_TAG(), $parentProductId);
  35.  
  36.             $masterProduct->save(false);
  37.             $masterProductId = $masterProduct->getPageId();
  38.         } else {
  39.             $masterProductId = current($masterProducts);
  40.         }
  41.  
  42.         if ($page->getParentPageId() != $masterProductId) {
  43.             $page->setParentPageId($masterProductId);
  44.         }
  45.  
  46.         $page->setPageTypeId(\Buxus\Util\PageTypeID::ESHOP_PRODUCT_VARIANT_ID());
  47.  
  48.         return $cell->getValue();
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top