Skip to content

Commit

Permalink
Merge pull request #14 from EaDesgin/feature/2232-Fix-bug-items
Browse files Browse the repository at this point in the history
#2232: Commit with fix bug two extension in json.
  • Loading branch information
eadesignro committed May 11, 2018
2 parents fbe5f58 + 23b539e commit f3b87ac
Showing 1 changed file with 41 additions and 31 deletions.
72 changes: 41 additions & 31 deletions Controller/Index/Packagist.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\Customer\Controller\AbstractAccount;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Api\FilterBuilder;

/**
* Class Packagist
Expand Down Expand Up @@ -71,9 +72,14 @@ class Packagist extends AbstractAccount
* @var SearchCriteriaBuilder
*/
private $searchCriteria;
/**
* @var FilterBuilder
*/
private $filterBuilder;

private $jsonResultFactory;


/**
* Packagist constructor.
* @param Context $context
Expand All @@ -89,6 +95,7 @@ class Packagist extends AbstractAccount
* @param CustomerPackagesFactory $customerPackagesFactory
* @param CustomerAuthRepository $customerAuthRepository
* @param SearchCriteriaBuilder $searchCriteria
* @param FilterBuilder $filterBuilder
*/

public function __construct(
Expand All @@ -105,22 +112,24 @@ public function __construct(
CustomerPackagesFactory $customerPackagesFactory,
CustomerAuthRepository $customerAuthRepository,
SearchCriteriaBuilder $searchCriteria,
FilterBuilder $filterBuilder,
\Magento\Framework\Controller\Result\JsonFactory $jsonResultFactory
) {
parent::__construct($context);
$this->session = $session;
$this->packages = $packages;
$this->resultJsonFactory = $resultJsonFactory;
$this->packagesRepository = $packagesRepository;
$this->customerPackages = $customerPackages;
$this->session = $session;
$this->packages = $packages;
$this->resultJsonFactory = $resultJsonFactory;
$this->packagesRepository = $packagesRepository;
$this->customerPackages = $customerPackages;
$this->customerPackagesRepository = $customerPackagesRepository;
$this->composerRepoRepository = $composerRepoRepository;
$this->customerAuth = $customerAuth;
$this->customerAuthFactory = $customerAuthFactory;
$this->customerPackagesFactory = $customerPackagesFactory;
$this->customerAuthRepository = $customerAuthRepository;
$this->searchCriteria = $searchCriteria;
$this->jsonResultFactory = $jsonResultFactory;
$this->composerRepoRepository = $composerRepoRepository;
$this->customerAuth = $customerAuth;
$this->customerAuthFactory = $customerAuthFactory;
$this->customerPackagesFactory = $customerPackagesFactory;
$this->customerAuthRepository = $customerAuthRepository;
$this->searchCriteria = $searchCriteria;
$this->jsonResultFactory = $jsonResultFactory;
$this->filterBuilder = $filterBuilder;
}

public function execute()
Expand All @@ -132,12 +141,10 @@ public function execute()
return false;
}

$authCriteriaBuilder = $this->searchCriteria;
$authCriteria = $authCriteriaBuilder->addFilter(
'auth_key',
$authKey,
'eq'
)->create();
$searchCriteriaBuilder = $this->searchCriteria;
$authCriteria = $searchCriteriaBuilder
->addFilter('auth_key', $authKey, 'eq')
->create();

$authList = $this->customerAuthRepository->getList($authCriteria);
$items = $authList->getItems();
Expand Down Expand Up @@ -165,38 +172,41 @@ public function execute()
$customerPackage = $customerPackages->getItems();

foreach ($customerPackage as $customerData) {
$packageId = $customerData->getData('package_id');
$packageId[] = $customerData->getData('package_id');
}

$packageFilter[] = $this->filterBuilder
->setField('entity_id')
->setValue($packageId)
->setConditionType('in')
->create();


$searchCriteriaBuilder = $this->searchCriteria;
$searchCriteria = $searchCriteriaBuilder
->addFilter('entity_id', $packageId)
->addFilters($packageFilter)
->create();
$packages = $this->packagesRepository->getList($searchCriteria);
$items = $packages->getItems();

foreach ($items as $packageId) {
$packageJson = $packageId->getData('package_json');
$name = $packageId->getData('name');
$decodeJson = json_decode($packageJson);
$decodeJson[$name] = json_decode($packageJson);
}

if ($customerId && $packageId) {
$responseData = [
'notify-batch' => 'https://www.eadesign.ro/eadesign_composerrepo/index/packagist/',
'cached' => false,
'packages' => [
$name => $decodeJson,
]
];
$responseData = [
'notify-batch' => 'https://www.eadesign.ro/eadesign_composerrepo/index/packagist/',
'cached' => false,
'packages' => [$decodeJson]
];

if ($customerId && $packageId) {
$res = json_encode($responseData, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$resultJson = $this->resultJsonFactory->create();
$response = $resultJson->setJsonData($res);
}

return $response;

}

public function unAuthResponse()
Expand Down

0 comments on commit f3b87ac

Please sign in to comment.