Skip to content

Commit

Permalink
Version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrzk committed Sep 5, 2022
0 parents commit 3b7a025
Show file tree
Hide file tree
Showing 34 changed files with 2,314 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Api/Json/BaseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. (MIT License)
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\GmailMarkup\Api\Json;

interface BaseInterface
{
public const CONTEXT = '@context';
public const TYPE = '@type';
public const MERCHANT = 'merchant';
public const SCHEMA_HTTP = 'http://schema.org';
public const NAME = 'name';
public const POTENTIAL_ACTION = 'potentialAction';
public const URL = 'url';

public const TYPE_PERSON = 'Person';
public const TYPE_PAYMENT_METHOD = 'PaymentMethod';
public const TYPE_VIEW_ACTION = 'ViewAction';
public const TYPE_POSTAL_ADDRESS = 'PostalAddress';
public const TYPE_QUANTITATIVE_VALUE = 'QuantitativeValue';
public const TYPE_PRODUCT = 'Product';
public const TYPE_OFFER = 'Offer';
public const TYPE_ORDER = 'Order';
public const TYPE_ORGANIZATION = 'Organization';
public const TYPE_TRACK_ACTION = 'TrackAction';
public const TYPE_PARCEL_SERVICE = 'ParcelService';
public const TYPE_PARCEL_DELIVERY = 'ParcelDelivery';
}
33 changes: 33 additions & 0 deletions Api/Json/OrderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. (MIT License)
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\GmailMarkup\Api\Json;

interface OrderInterface
{
public const ORDER_NUMBER = 'orderNumber';
public const ORDER_STATUS = 'orderStatus';
public const PRICE_CURRENCY = 'priceCurrency';
public const PRICE = 'price';
public const ACCEPTED_OFFER = 'acceptedOffer';
public const ITEM_OFFERED = 'itemOffered';
public const NAME = 'name';
public const ELIGIBLE_QUANTITY = 'eligibleQuantity';
public const VALUE = 'value';
public const URL = 'url';
public const ORDER_DATE = 'orderDate';
public const BILLING_ADDRESS = 'billingAddress';
public const STREET_ADDRESS = 'streetAddress';
public const ADDRESS_LOCALITY = 'addressLocality';
public const ADDRESS_REGION = 'addressRegion';
public const ADDRESS_COUNTRY = 'addressCountry';
public const PAYMENT_METHOD = 'paymentMethod';
public const CUSTOMER = 'customer';
public const DISCOUNT = 'discount';
public const DISCOUNT_CURRENCY = 'discountCurrency';
}
19 changes: 19 additions & 0 deletions Api/Json/ProductInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. (MIT License)
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\GmailMarkup\Api\Json;

interface ProductInterface
{
public const NAME = 'name';
public const URL = 'url';
public const IMAGE = 'image';
public const SKU = 'sku';
public const DESCRIPTION = 'description';
public const BRAND = 'brand';
}
30 changes: 30 additions & 0 deletions Api/Json/ShipmentInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. (MIT License)
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\GmailMarkup\Api\Json;

interface ShipmentInterface
{
public const ORDER_NUMBER = 'orderNumber';
public const ORDER_STATUS = 'orderStatus';
public const ITEM_SHIPPED = 'itemShipped';
public const TRACKING_NUMBER = 'trackingNumber';
public const TRACKING_URL = 'trackingUrl';
public const URL = 'url';
public const EXPECTED_ARRIVAL_UNTIL = 'expectedArrivalUntil';
public const CARRIER = 'carrier';
public const VALUE = 'value';
public const PART_OF_ORDER = 'partOfOrder';
public const DELIVERY_ADDRESS = 'deliveryAddress';
public const NAME = 'name';
public const STREET_ADDRESS = 'streetAddress';
public const ADDRESS_LOCALITY = 'addressLocality';
public const ADDRESS_REGION = 'addressRegion';
public const ADDRESS_COUNTRY = 'addressCountry';
public const POSTAL_CODE = 'postalCode';
}
21 changes: 21 additions & 0 deletions Api/OrderStatusInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. (MIT License)
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\GmailMarkup\Api;

interface OrderStatusInterface
{
public const CANCELLED = 'http://schema.org/OrderCancelled';
public const DELIVERED = 'http://schema.org/OrderDelivered';
public const IN_TRANSIT = 'http://schema.org/OrderInTransit';
public const PAYMENT_DUE = 'http://schema.org/OrderPaymentDue';
public const PICKUP_AVAILABLE = 'http://schema.org/OrderPickupAvailable';
public const PROBLEM = 'http://schema.org/OrderProblem';
public const PROCESSING = 'http://schema.org/OrderProcessing';
public const RETURNED = 'http://schema.org/OrderReturned';
}
77 changes: 77 additions & 0 deletions Block/Adminhtml/Form/Field/DeliveryColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. (MIT License)
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\GmailMarkup\Block\Adminhtml\Form\Field;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\Element\Context;
use Magento\Framework\View\Element\Html\Select;
use Magento\Shipping\Model\Config\Source\Allmethods;
use Magento\Store\Model\ScopeInterface;

class DeliveryColumn extends Select
{
private Allmethods $allmethods;

/**
* @param Allmethods $allmethods
* @param Context $context
* @param array $data
*/
public function __construct(
Allmethods $allmethods,
Context $context,
array $data = []
) {
parent::__construct($context, $data);

$this->allmethods = $allmethods;
}

/**
* @param string $value
*
* @return $this
*/
public function setInputName($value)
{
/* @phpstan-ignore-next-line */
return $this->setName($value);
}

/**
* @param mixed $value
*
* @return $this
*/
public function setInputId($value)
{
return $this->setId($value);
}

/**
* @return string
*/
public function _toHtml(): string
{
if (!$this->getOptions()) {
$this->setOptions($this->getSourceOptions());
}

return parent::_toHtml();
}

/**
* @return array
*/
private function getSourceOptions(): array
{
return $this->allmethods->toOptionArray();
}
}
73 changes: 73 additions & 0 deletions Block/Adminhtml/Form/Field/DeliveryOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. (MIT License)
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\GmailMarkup\Block\Adminhtml\Form\Field;

use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
use Magento\Framework\DataObject;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\View\Element\BlockInterface;

class DeliveryOptions extends AbstractFieldArray
{
/** @var Types|BlockInterface */
private $typeRenderer = null;

/**
* @return void
* @throws LocalizedException
*/
protected function _prepareToRender()
{
$this->addColumn('delivery_method', [
'label' => __('Delivery Method'),
'renderer' => $this->getDeliveryMethodRenderer()
]);

$this->addColumn('delivery_name', [
'label' => __('Delivery JSON Name'),
'class' => 'required-entry'
]);

$this->_addAfter = false;
$this->_addButtonLabel = __('Add')->render();
}

/**
* @return Types|BlockInterface
* @throws LocalizedException
*/
private function getDeliveryMethodRenderer()
{
$this->typeRenderer = $this->getLayout()->createBlock(
DeliveryColumn::class,
'',
['data' => ['is_render_to_js_template' => true]]
);

return $this->typeRenderer;
}

/**
* @param DataObject $row
*
* @throws LocalizedException
*/
protected function _prepareArrayRow(DataObject $row): void
{
$options = [];
$type = $row->getDeliveryMethod();

if ($type !== null) {
/* @phpstan-ignore-next-line */
$options['option_' . $this->getDeliveryMethodRenderer()->calcOptionHash($type)] = 'selected="selected"';
}

$row->setData('option_extra_attrs', $options);
}
}
78 changes: 78 additions & 0 deletions Block/Adminhtml/Form/Field/OrderMagentoColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. (MIT License)
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\GmailMarkup\Block\Adminhtml\Form\Field;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\Element\Context;
use Magento\Framework\View\Element\Html\Select;
use Magento\Store\Model\ScopeInterface;

use Magento\Sales\Model\ResourceModel\Order\Status\Collection as OrderStatusCollection;

class OrderMagentoColumn extends Select
{
private OrderStatusCollection $orderStatusCollection;

/**
* @param OrderStatusCollection $orderStatusCollection
* @param Context $context
* @param array $data
*/
public function __construct(
OrderStatusCollection $orderStatusCollection,
Context $context,
array $data = []
) {
parent::__construct($context, $data);

$this->orderStatusCollection = $orderStatusCollection;
}

/**
* @param string $value
*
* @return $this
*/
public function setInputName($value)
{
/* @phpstan-ignore-next-line */
return $this->setName($value);
}

/**
* @param mixed $value
*
* @return $this
*/
public function setInputId($value)
{
return $this->setId($value);
}

/**
* @return string
*/
public function _toHtml(): string
{
if (!$this->getOptions()) {
$this->setOptions($this->getSourceOptions());
}

return parent::_toHtml();
}

/**
* @return array
*/
private function getSourceOptions(): array
{
return $this->orderStatusCollection->toOptionArray();
}
}
Loading

0 comments on commit 3b7a025

Please sign in to comment.