Skip to content

Commit

Permalink
Merge pull request #37 from searchspring/client/sprinklerwarehouse
Browse files Browse the repository at this point in the history
Add ability to specify customerId as part of request
  • Loading branch information
James Bathgate authored May 6, 2021
2 parents 6160d30 + 2950de6 commit dca4bf9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Helper/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -122,6 +128,8 @@ public function __construct(
ProductVisibility $productVisibility,
ProductOptionFactory $productOptionFactory,
ProductCollectionFactory $productCollectionFactory,
CustomerFactory $customerFactory,
SessionFactory $sessionFactory,
ProductRepositoryInterface $productRepository,
StockItemRepository $stockItemRepository,
ImageHelper $productImageHelper,
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="SearchSpring_Feed" setup_version="1.1.2"/>
<module name="SearchSpring_Feed" setup_version="1.1.3"/>
</config>

0 comments on commit dca4bf9

Please sign in to comment.