Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12918-purchase-event-on-speciifc-order-status-only #44

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Block/Adminhtml/System/Config/Form/InfoAllowedOrderStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © Magefan ([email protected]). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/

declare(strict_types=1);

namespace Magefan\GoogleTagManager\Block\Adminhtml\System\Config\Form;

class InfoAllowedOrderStatus extends InfoPlan
{
/**
* @return string
*/
protected function getMinPlan(): string
{
return 'Extra';
}

/**
* @return string
*/
protected function getSectionId(): string
{
return 'mfgoogletagmanager_events_purchase_allowed_order_status';
}

/**
* @return string
*/
protected function getText(): string
{
return '';
}
}
57 changes: 57 additions & 0 deletions Model/Config/Source/OrderStatuses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Copyright © Magefan ([email protected]). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/

declare(strict_types=1);

namespace Magefan\GoogleTagManager\Model\Config\Source;

use Magento\Sales\Model\Config\Source\Order\Status as StatusModel;
use Magento\Framework\Option\ArrayInterface;

class OrderStatuses implements ArrayInterface
{
/**
* @var StatusModel
*/
protected $statusModel;

protected $optionArray;

/**
* @param StatusModel $statusModel
*/
public function __construct(
StatusModel $statusModel
) {
$this->statusModel = $statusModel;
}

/**
* @return array[]
*/
public function toOptionArray()
{
if (!isset($this->optionArray)) {
$this->optionArray = [];
$this->optionArray[] = ['value' => __('any'), 'label' => __('Any status')];

$statuses = $this->statusModel->toOptionArray();
foreach ($statuses as $status) {
if (!isset($status['value']) || !isset($status['label'])) {
continue;
}

if (!$status['value'] || !$status['label']) {
continue;
}

$this->optionArray[] = ['value' => (string)$status['value'], 'label' => (string)$status['label']];
}
}

return $this->optionArray;
}
}
12 changes: 12 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,18 @@ To create a new secret, navigate in the
<label>Track Admin Orders (GTM Extra) </label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="info_allowed_order_status" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<frontend_model>Magefan\GoogleTagManager\Block\Adminhtml\System\Config\Form\InfoAllowedOrderStatus</frontend_model>
</field>
<field id="allowed_order_status" translate="label" type="multiselect" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Allowed Order Status (Extra) </label>
<source_model>Magefan\GoogleTagManager\Model\Config\Source\OrderStatuses</source_model>
<comment><![CDATA[
<p>Only orders with this status will be tracked.</p>
<p><strong>Note:</strong> This option will be ignored if the GTM Server Container or the Measurement Protocol is disabled.</p>
]]>
</comment>
</field>
</group>
</group>
<group id="page_speed_optimization" translate="label" type="text" sortOrder="65" showInDefault="1" showInWebsite="1" showInStore="1">
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<shipping_enabled>1</shipping_enabled>
<tax_enabled>1</tax_enabled>
<track_admin_orders>1</track_admin_orders>
<allowed_order_status>any</allowed_order_status>
</purchase>
</events>
<page_speed_optimization>
Expand Down