Skip to content

Commit

Permalink
Ghost dependency with Smile_RetailerOffer #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanny DECLERCK committed Jul 15, 2019
1 parent db7f169 commit 7e48fb7
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
92 changes: 92 additions & 0 deletions Ui/Component/Form/Retailer/Options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @category Smile
* @package Smile\Retailer
* @author Fanny DECLERCK <[email protected]>
* @copyright 2019 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\Retailer\Ui\Component\Form\Retailer;

use Magento\Framework\Data\OptionSourceInterface;
use Magento\Framework\App\RequestInterface;
use Smile\Retailer\Model\ResourceModel\Retailer\CollectionFactory;

/**
* Source Model for Retailer Picker
*
* @category Smile
* @package Smile\Retailer
* @author Fanny DECLERCK <[email protected]>
*/
class Options implements OptionSourceInterface
{
/**
* @var \Smile\Retailer\Model\ResourceModel\Retailer\CollectionFactory
*/
protected $retailerCollectionFactory;

/**
* @var RequestInterface
*/
protected $request;

/**
* @var array
*/
protected $retailersList;

/**
* @param CollectionFactory $retailerCollectionFactory The Retailer Collection Factory
* @param RequestInterface $request The application request
*/
public function __construct(
CollectionFactory $retailerCollectionFactory,
RequestInterface $request
) {
$this->retailerCollectionFactory = $retailerCollectionFactory;
$this->request = $request;
}

/**
* {@inheritdoc}
*/
public function toOptionArray()
{
return $this->getRetailerList();
}

/**
* Retrieve retailer tree
*
* @return array
*/
protected function getRetailerList()
{
if ($this->retailersList === null) {
$this->retailersList = [];
$storeId = $this->request->getParam('store');

/* @var $collection \Smile\Seller\Model\ResourceModel\Seller\Collection */
$collection = $this->retailerCollectionFactory->create();

$collection
->addAttributeToSelect(['name', 'is_active'])
->setStoreId($storeId);

foreach ($collection as $retailer) {
$this->retailersList[$retailer->getId()] = [
'value' => $retailer->getId(),
'is_active' => $retailer->getIsActive(),
'label' => $retailer->getName(),
];
}
}

return $this->retailersList;
}
}
24 changes: 24 additions & 0 deletions etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<!--
/**
* Smile_Retailer Adminhtml dependency injection configuration.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @category Smile
* @package Smile\Retailer
* @author Fanny DECLERCK <[email protected]>
* @copyright 2019 Smile
* @license Open Software License ("OSL") v. 3.0
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Smile\Retailer\Ui\Component\Form\Retailer\Options">
<arguments>
<argument name="retailerCollectionFactory" xsi:type="object">Smile\Retailer\Model\ResourceModel\Retailer\CollectionFactory</argument>
</arguments>
</type>
</config>

0 comments on commit 7e48fb7

Please sign in to comment.