diff --git a/Helper/Generator.php b/Helper/Generator.php index 4ec8682..801bf9d 100644 --- a/Helper/Generator.php +++ b/Helper/Generator.php @@ -27,6 +27,8 @@ use \Magento\Catalog\Model\Product\Gallery\ReadHandler as GalleryReadHandler; use \Magento\Catalog\Model\Product\OptionFactory as ProductOptionFactory; use \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory; +use \Magento\Customer\Model\CustomerFactory as CustomerFactory; +use \Magento\Customer\Model\SessionFactory as SessionFactory; use \Magento\Catalog\Model\ResourceModel\Eav\Attribute as AttributeFactory; use \Magento\CatalogInventory\Api\StockRegistryInterface as StockRegistryInterface; use \Magento\CatalogInventory\Helper\Stock as StockFilter; @@ -59,6 +61,8 @@ class Generator extends \Magento\Framework\App\Helper\AbstractHelper { protected $productCollectionFactory; protected $productOptionFactory; + protected $customerFactory; + protected $sessionFactory; protected $productRepositoryInterface; protected $productVisibility; protected $stockItemRepository; @@ -94,6 +98,8 @@ class Generator extends \Magento\Framework\App\Helper\AbstractHelper { protected $includeChildPrices = false; protected $includeTierPricing = false; + protected $customerId; + // Extra image types to include, by default we only include product_thumbnail_image protected $imageTypes = array(); @@ -122,6 +128,8 @@ public function __construct( ProductVisibility $productVisibility, ProductOptionFactory $productOptionFactory, ProductCollectionFactory $productCollectionFactory, + CustomerFactory $customerFactory, + SessionFactory $sessionFactory, ProductRepositoryInterface $productRepository, StockItemRepository $stockItemRepository, ImageHelper $productImageHelper, @@ -186,6 +194,8 @@ public function __construct( $this->includeChildPrices = $this->request->getParam('includeChildPrices', 0); $this->includeTierPricing = $this->request->getParam('includeTierPricing', 0); + $this->customerId = $this->request->getParam('customerId'); + $this->imageTypes = $this->request->getParam('imageTypes', array()); if(!is_array($this->imageTypes)) { @@ -229,6 +239,18 @@ public function __construct( // TODO explore using CSV writer built into Magento, it looks like it can only write whole file and not append $this->tmpFile = fopen($this->feedPath . '/' . $this->tmpFilename, 'a'); + + // If a customerId is passed act as a certain user for product/category permissions + if($this->customerId) { + // Load customer based upon ID + $customer = $customerFactory->create()->load($this->customerId); + + // Create session + $sessionManager = $sessionFactory->create(); + + // Log in as customer + $sessionManager->setCustomerAsLoggedIn($customer); + } } public function generate() diff --git a/composer.json b/composer.json index d2c4d5b..b8bee49 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "searchspring/module-feed", "description": "Module to generate a SearchSpring CSV Feed", "type": "magento2-module", - "version": "1.1.2", + "version": "1.1.3", "license": "GPL-3.0", "authors": [ { diff --git a/etc/module.xml b/etc/module.xml index 30b870c..e746d1b 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,4 +1,4 @@ - +