Skip to content

Commit

Permalink
Merge pull request #5 from gento-arg/sucursales_agrupadas
Browse files Browse the repository at this point in the history
Sucursales agrupadas
  • Loading branch information
manuelcanepa authored May 20, 2021
2 parents 5ce83fb + 6995219 commit 2d451b6
Show file tree
Hide file tree
Showing 33 changed files with 1,021 additions and 136 deletions.
61 changes: 61 additions & 0 deletions Controller/Ajax/Branches.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Gento\Oca\Controller\Ajax;

use Gento\Oca\Helper\Data;
use Gento\Oca\Model\OcaApi;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\Result\JsonFactory;

/**
* Catalog index page controller.
*/
class Branches extends Action implements HttpPostActionInterface
{
/**
* @var JsonFactory
*/
protected $resultJsonFactory;

/**
* @var OcaApi
*/
protected $ocaApi;

/**
* @var Data
*/
protected $helper;

/**
* Branches constructor.
* @param JsonFactory $resultJsonFactory
* @param OcaApi $ocaApi
* @param Context $context
* @param Data $helper
*/
public function __construct(
JsonFactory $resultJsonFactory,
OcaApi $ocaApi,
Context $context,
Data $helper
) {
$this->resultJsonFactory = $resultJsonFactory;
$this->ocaApi = $ocaApi;
$this->helper = $helper;
parent::__construct($context);
}

public function execute()
{
$result = $this->resultJsonFactory->create();

$zipcode = $this->getRequest()->getParam('zipcode');
$branches = $this->ocaApi->getBranchesZipCode($zipcode);
$branches = $this->helper->addDescriptionToBranches($branches);

return $result->setData($branches);
}
}
42 changes: 41 additions & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Gento\Oca\Model\Config\Source\UnitsAttribute;
use Magento\Catalog\Model\Product;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Filter\FilterManager;
use Magento\Store\Model\ScopeInterface;

class Data
Expand All @@ -15,9 +16,11 @@ class Data
protected $scopeConfig;

public function __construct(
ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig,
FilterManager $filterManager
) {
$this->scopeConfig = $scopeConfig;
$this->filterManager = $filterManager;
}

public function getProductSize(Product $product)
Expand Down Expand Up @@ -51,6 +54,43 @@ public function getProductSize(Product $product)
return [$width, $height, $length];
}

/**
* @param $branches
* @return array[]
*/
public function addDescriptionToBranches($branches)
{
foreach ($branches as $idx => $branch) {
$branches[$idx] = $this->addDescriptionToBranch($branch);
}
return $branches;
}

/**
* @param array $branch
* @return array
*/
public function addDescriptionToBranch(array $branch)
{
$branch['branch_description'] = $this->getParsedDescription($branch);
return $branch;
}

/**
* @param array $branch
* @return string
*/
protected function getParsedDescription(array $branch)
{
$template = $this->getConfigData('carriers/gento_oca/branch_description');

return $this->filterManager->template($template, ['variables' => $branch]);
}

/**
* @param $path
* @return mixed
*/
protected function getConfigData($path)
{
return $this->scopeConfig->getValue(
Expand Down
Loading

0 comments on commit 2d451b6

Please sign in to comment.