Skip to content
Snippets Groups Projects
Commit 880e28e7 authored by Gundo Sifhufhi's avatar Gundo Sifhufhi
Browse files

Magento extension registration & Initial Setup Files

parent 3a325095
No related branches found
No related tags found
No related merge requests found
Showing
with 531 additions and 0 deletions
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PublishConfigData" remoteFilesAllowedToDisappearOnAutoupload="false">
<serverData>
<paths name="Local or mounted folder">
<serverdata>
<mappings>
<mapping local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>
</serverData>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/magento-uafrica-shipping-extension.iml" filepath="$PROJECT_DIR$/.idea/magento-uafrica-shipping-extension.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?php
namespace uafrica\Customshipping\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
/**
* @category BobGroup
* @package uafrica_customshipping
* @author info@bob.co.za
* @website https://www.bob.co.za
*/
class Version extends \Magento\Config\Block\System\Config\Form\Field
{
const EXTENSION_URL = 'https://www.bob.co.za';
/**
* @var \uafrica\Customshipping\Helper\Data $helper
*/
protected $_helper;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \uafrica\Customshipping\Helper\Data $helper
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\uafrica\Customshipping\Helper\Data $helper
) {
$this->_helper = $helper;
parent::__construct($context);
}
/**
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
$extensionVersion = $this->_helper->getExtensionVersion();
$extensionTitle = 'BobGo';
$versionLabel = sprintf(
'<a href="%s" title="%s" target="_blank">%s</a>',
self::EXTENSION_URL,
$extensionTitle,
$extensionVersion
);
$element->setValue($versionLabel);
return $element->getValue();
}
}
<?php
namespace uafrica\Customshipping\Helper;
/**
* @category uafrica
* @package uafrica_customshipping
* @author uafrica
* @website https://www.bob.co.za
*/
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
const XML_PATH_ENABLED = 'uafrica_customshipping/general/enabled';
const XML_PATH_DEBUG = 'uafrica_customshipping/general/debug';
/**
* @var \Psr\Log\LoggerInterface
*/
protected $_logger;
/**
* @var \Magento\Framework\Module\ModuleListInterface
*/
protected $_moduleList;
/**
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\Module\ModuleListInterface $moduleList
) {
$this->_logger = $context->getLogger();
$this->_moduleList = $moduleList;
parent::__construct($context);
}
/**
* Check if enabled
*
* @return string|null
*/
public function isEnabled()
{
return $this->scopeConfig->getValue(
self::XML_PATH_ENABLED,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
public function getDebugStatus()
{
return $this->scopeConfig->getValue(
self::XML_PATH_DEBUG,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
public function getExtensionVersion()
{
$moduleCode = 'uafrica_Customshipping';
$moduleInfo = $this->_moduleList->getOne($moduleCode);
return $moduleInfo['setup_version'];
}
/**
*
* @param $message
* @param bool|false $useSeparator
*/
public function log($message, $useSeparator = false)
{
if ($this->getDebugStatus()) {
if ($useSeparator) {
$this->_logger->addDebug(str_repeat('=', 100));
}
$this->_logger->addDebug($message);
}
}
}
<?php
namespace uafrica\Customshipping\Model\Carrier;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\DataObject;
use Magento\Shipping\Model\Carrier\AbstractCarrier;
use Magento\Shipping\Model\Carrier\CarrierInterface;
use Magento\Shipping\Model\Config;
use Magento\Shipping\Model\Rate\ResultFactory;
use Magento\Store\Model\ScopeInterface;
use Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory;
use Magento\Quote\Model\Quote\Address\RateResult\Method;
use Magento\Quote\Model\Quote\Address\RateResult\MethodFactory;
use Magento\Quote\Model\Quote\Address\RateRequest;
use Psr\Log\LoggerInterface;
/**
* @category uafrica
* @package uafrica_Customshipping
* @author info@bob.co.za
* @website https://www.bob.co.za
*/
class Customshipping extends AbstractCarrier implements CarrierInterface
{
/**
* Carrier's code
*
* @var string
*/
protected $_code = 'uafrica';
/**
* Whether this carrier has fixed rates calculation
*
* @var bool
*/
protected $_isFixed = true;
/**
* @var ResultFactory
*/
protected $_rateResultFactory;
/**
* @var MethodFactory
*/
protected $_rateMethodFactory;
/**
* @param ScopeConfigInterface $scopeConfig
* @param ErrorFactory $rateErrorFactory
* @param LoggerInterface $logger
* @param ResultFactory $rateResultFactory
* @param MethodFactory $rateMethodFactory
* @param array $data
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
ErrorFactory $rateErrorFactory,
LoggerInterface $logger,
ResultFactory $rateResultFactory,
MethodFactory $rateMethodFactory,
array $data = []
) {
$this->_rateResultFactory = $rateResultFactory;
$this->_rateMethodFactory = $rateMethodFactory;
parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);
}
/**
* Generates list of allowed carrier`s shipping methods
* Displays on cart price rules page
*
* @return array
* @api
*/
public function getAllowedMethods()
{
return [$this->getCarrierCode() => __($this->getConfigData('name'))];
}
/**
* Collect and get rates for storefront
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @param RateRequest $request
* @return DataObject|bool|null
* @api
*/
public function collectRates(RateRequest $request)
{
/**
* Make sure that Shipping method is enabled
*/
if (!$this->isActive()) {
return false;
}
/** @var \Magento\Shipping\Model\Rate\Result $result */
$result = $this->_rateResultFactory->create();
$shippingPrice = $this->getConfigData('price');
$method = $this->_rateMethodFactory->create();
/**
* Set carrier's method data
*/
$method->setCarrier($this->getCarrierCode());
$method->setCarrierTitle($this->getConfigData('title'));
/**
* Displayed as shipping method under Carrier
*/
$method->setMethod($this->getCarrierCode());
$method->setMethodTitle($this->getConfigData('name'));
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
return $result;
}
}
{
"name": "uafrica/bobgo",
"description": "Streamline your shipments and order fulfilments with bobgo",
"type": "magento2-module",
"version": "1.0.0",
"authors": [
{
"name": "Gundo Sifhufhi",
"email": "gundo@bob.co.za",
"homepage": "https://www.bob.co.za"
}
],
"license": [
" Apache-2.0"
],
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0|~7.1.0"
},
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"uafrica\\Customshipping\\": ""
}
}
}
<?xml version="1.0"?>
<!--
/**
* @category Uafrica
* @package Uafrica_Customshipping
* @author Uafrica
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="uafrica" translate="label" sortOrder="200">
<label>uafrica</label>
</tab>
<section id="uafrica_customshipping" showInDefault="1">
<tab>uafrica</tab>
<label>bobGo</label>
<resource>Magento_Config::config</resource>
<group id="general" showInDefault="1">
<label>General Settings</label>
<field id="version" translate="label" type="label" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Version</label>
<frontend_model>uafrica\Customshipping\Block\System\Config\Form\Field\Version</frontend_model>
</field>
<!--<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>-->
<field id="debug" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Debug Mode</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
<section id="carriers" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<group id="uafrica" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>bobGo</label>
<field id="version" translate="label" type="label" sortOrder="0" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Version</label>
<frontend_model>uafrica\Customshipping\Block\System\Config\Form\Field\Version</frontend_model>
</field>
<!-- <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0">-->
<!-- <label>Enabled</label>-->
<!-- <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>-->
<!-- </field>-->
<field id="title" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Title</label>
</field>
<field id="name" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Method Name</label>
</field>
<field id="price" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Shipping Cost</label>
<validate>validate-number validate-zero-or-greater</validate>
</field>
<field id="specificerrmsg" translate="label" type="textarea" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Displayed Error Message</label>
</field>
<field id="sallowspecific" translate="label" type="select" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Ship to Applicable Countries</label>
<frontend_class>shipping-applicable-country</frontend_class>
<source_model>Magento\Shipping\Model\Config\Source\Allspecificcountries</source_model>
</field>
<field id="specificcountry" translate="label" type="multiselect" sortOrder="91" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Ship to Specific Countries</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
<can_be_empty>1</can_be_empty>
</field>
<field id="showmethod" translate="label" type="select" sortOrder="92" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Show Method if Not Applicable</label>
<frontend_class>shipping-skip-hide</frontend_class>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="sort_order" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Sort Order</label>
</field>
</group>
</section>
</system>
</config>
<?xml version="1.0"?>
<!--
/**
* @category Uafrica
* @package Uafrica_Customshipping
* @author Uafrica
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<uafrica_customshipping>
<general>
<debug>0</debug>
</general>
</uafrica_customshipping>
<carriers>
<uafrica>
<active>0</active>
<sallowspecific>0</sallowspecific>
<price>0</price>
<model>uafrica\Customshipping\Model\Carrier\Customshipping</model>
<name>Fixed</name>
<title>bobGo</title>
<specificerrmsg>This shipping method is not available. To use this shipping method, please contact us.</specificerrmsg>
</uafrica>
</carriers>
</default>
</config>
<?xml version="1.0"?>
<!--
/**
* @category Uafrica
* @package Uafrica_Customshipping
* @author Uafrica
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="uafrica_Customshipping" setup_version="1.0.0">
</module>
</config>
"Enabled","Enabled"
\ No newline at end of file
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'uafrica_Customshipping',
__DIR__
);
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.cart.shipping">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="summary-block-config" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-rates-validation" xsi:type="array">
<item name="children" xsi:type="array">
<item name="uafrica-rates-validation" xsi:type="array">
<item name="component" xsi:type="string">uafrica_Customshipping/js/view/shipping-rates-validation</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="step-config" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-rates-validation" xsi:type="array">
<item name="children" xsi:type="array">
<item name="uafrica-rates-validation" xsi:type="array">
<item name="component" xsi:type="string">uafrica_Customshipping/js/view/shipping-rates-validation</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment