b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / Acx / StorePickup / Model /
Filename/home/dev2.destoffenstraat.com/app/code/Acx/StorePickup/Model/Carrier.php
Size3.97 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified06-Apr-2021 18:06
Last accessed21-Aug-2025 22:38
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
namespace Acx\StorePickup\Model;

use Acx\StorePickup\Block\System\Config\Form\Field\Locations;

class Carrier extends \Magento\Shipping\Model\Carrier\AbstractCarrier implements \Magento\Shipping\Model\Carrier\AbstractCarrierInterface
{

const CODE = 'storepickup';

protected $_code = self::CODE;

/**
* @var \Magento\Shipping\Model\Rate\ResultFactory
*/
private $shippingRateResultFactory;

/**
* @var \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory
*/
private $quoteQuoteAddressRateResultMethodFactory;

public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory,
\Psr\Log\LoggerInterface $logger,
\Magento\Shipping\Model\Rate\ResultFactory $shippingRateResultFactory,
\Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $quoteQuoteAddressRateResultMethodFactory,
\Magento\Framework\Serialize\Serializer\Json $serialize,
array $data = []
) {
$this->shippingRateResultFactory = $shippingRateResultFactory;
$this->quoteQuoteAddressRateResultMethodFactory = $quoteQuoteAddressRateResultMethodFactory;
$this->serialize = $serialize;
parent::__construct(
$scopeConfig,
$rateErrorFactory,
$logger,
$data
);
}

public function collectRates(\Magento\Quote\Model\Quote\Address\RateRequest $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}

if (!$this->getConfigData('display_in_frontend')) {
return false;
}

$result = $this->shippingRateResultFactory->create();

if (!empty($result)) {

$locations = $this->getLocations();

foreach ($locations as $locationId => $location) {
$method = $this->quoteQuoteAddressRateResultMethodFactory->create();

$methodTitleAttributes = [];

foreach (Locations::ATTRIBUTES as $attr) {
$value = $location[$attr];

if (isset($value) && strlen($value) > 0) {
$methodTitleAttributes[] = $value;
}
}

$methodTitle = implode(', ', $methodTitleAttributes);

$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod($locationId);
$method->setMethodTitle(
__($methodTitle)
);

$price = $this->getFinalPriceWithHandlingFee(0);
$method->setPrice($price);

$method->setCost($this->getConfigData('handling'));

$result->append($method);
}
}

return $result;
}

private function getLocations() {
$locations = [];

$configData = $this->getConfigData('stores');

if (is_string($configData) && !empty($configData)) {
$locations = $this->serialize->unserialize($configData);
}

$result = [];

foreach ($locations as $location) {
$locationId = strtolower(preg_replace("/[^A-Za-z0-9]/", '', $location['title']));

$result[$locationId] = [
'title' => $location['title'],
'street' => $location['street'],
'phone' => $location['phone'],
'message' => $location['message']
];

$result[$locationId] = array_merge($result[$locationId]);
}

return $result;
}

/**
* Get allowed shipping methods
*
* @return array
*/
public function getAllowedMethods()
{
return array('StorePickup'=> __('In-Store Pickup'));
}
}