Skip to content

Store Tracking URL in DB as well as Tracking Code #10854

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

Closed
wants to merge 17 commits into from
Closed
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
4 changes: 4 additions & 0 deletions app/code/Magento/Sales/Api/Data/ShipmentTrackInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ interface ShipmentTrackInterface extends TrackInterface, ExtensibleDataInterface
* Track number.
*/
const TRACK_NUMBER = 'track_number';
/*
* Track URL.
*/
const TRACK_URL = 'track_url';
/*
* Description.
*/
Expand Down
29 changes: 29 additions & 0 deletions app/code/Magento/Sales/Api/Data/TrackUrlInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sales\Api\Data;

/**
* Shipment Track Creation interface.
*
* @api
*/
interface TrackUrlInterface
{
/**
* Sets the track URL for the shipment package.
*
* @param string $trackUrl
* @return $this
*/
public function setTrackUrl($trackUrl);

/**
* Gets the track URL for the shipment package.
*
* @return string Track URL.
*/
public function getTrackUrl();
}
21 changes: 20 additions & 1 deletion app/code/Magento/Sales/Model/Order/Shipment/Track.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Api\Data\ShipmentTrackInterface;
use Magento\Sales\Api\Data\TrackUrlInterface;
use Magento\Sales\Model\AbstractModel;

/**
Expand All @@ -16,7 +17,7 @@
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @since 100.0.2
*/
class Track extends AbstractModel implements ShipmentTrackInterface
class Track extends AbstractModel implements ShipmentTrackInterface, TrackUrlInterface
{
/**
* Code of custom carrier
Expand Down Expand Up @@ -224,6 +225,16 @@ public function getTrackNumber()
return $this->getData(ShipmentTrackInterface::TRACK_NUMBER);
}

/**
* Returns track_url
*
* @return string
*/
public function getTrackUrl()
{
return $this->getData(ShipmentTrackInterface::TRACK_URL);
}

/**
* Returns carrier_code
*
Expand Down Expand Up @@ -370,6 +381,14 @@ public function setTrackNumber($trackNumber)
return $this->setData(ShipmentTrackInterface::TRACK_NUMBER, $trackNumber);
}

/**
* {@inheritdoc}
*/
public function setTrackUrl($trackUrl)
{
return $this->setData(ShipmentTrackInterface::TRACK_URL, $trackUrl);
}

/**
* {@inheritdoc}
*/
Expand Down
22 changes: 22 additions & 0 deletions app/code/Magento/Sales/Model/Order/Shipment/TrackCreation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class TrackCreation implements ShipmentTrackCreationInterface
*/
private $trackNumber;

/**
* @var string
*/
private $trackUrl;

/**
* @var string
*/
Expand Down Expand Up @@ -51,6 +56,23 @@ public function setTrackNumber($trackNumber)
return $this;
}

/**
* {@inheritdoc}
*/
public function getTrackUrl()
{
return $this->trackUrl;
}

/**
* {@inheritdoc}
*/
public function setTrackUrl($trackUrl)
{
$this->trackUrl = $trackUrl;
return $this;
}

/**
* {@inheritdoc}
*/
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Sales/Setup/InstallSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,12 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
'64k',
[],
'Number'
)->addColumn(
'track_url',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'64k',
['nullable' => true, 'default' => null],
'Tracking URL'
)->addColumn(
'description',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
Expand Down
17 changes: 15 additions & 2 deletions app/code/Magento/Sales/Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
self::$connectionName
)
);

//sales_bestsellers_aggregated_yearly
$connection->dropForeignKey(
$installer->getTable('sales_bestsellers_aggregated_yearly', self::$connectionName),
Expand All @@ -62,7 +61,6 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
self::$connectionName
)
);

$installer->endSetup();
}
if (version_compare($context->getVersion(), '2.0.3', '<')) {
Expand Down Expand Up @@ -106,6 +104,21 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
]
);
}
if (version_compare($context->getVersion(), '2.1.0', '<')) {
$connection = $installer->getConnection(self::$connectionName);
$tableName = $installer->getTable('sales_shipment_track');
$connection->addColumn(
$tableName,
'track_url',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => '64k',
'nullable' => true,
'default' => null,
'comment' => 'Tracking URL'
]
);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Sales/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"magento/module-sales-sample-data": "Sample Data version:100.2.*"
},
"type": "magento2-module",
"version": "100.2.0-dev",
"version": "100.3.0-dev",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Sales/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_Sales" setup_version="2.0.7">
<module name="Magento_Sales" setup_version="2.1.0">
<sequence>
<module name="Magento_Rule"/>
<module name="Magento_Catalog"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
// @codingStandardsIgnoreFile

?>
<?php $_shipment = $block->getShipment() ?>
<?php $_order = $block->getOrder() ?>
<?php
/** @var \Magento\Framework\View\Element\Template $block */

$_shipment = $block->getShipment();
$_order = $block->getOrder();
?>
<?php if ($_shipment && $_order && $_shipment->getAllTracks()): ?>
<br />
<table class="shipment-track">
Expand All @@ -19,10 +23,25 @@
</tr>
</thead>
<tbody>
<?php foreach ($_shipment->getAllTracks() as $_item): ?>
<?php
foreach ($_shipment->getAllTracks() as $_item): ?>
<tr>
<td><?= $block->escapeHtml($_item->getTitle()) ?>:</td>
<td><?= $block->escapeHtml($_item->getNumber()) ?></td>
<td>
<?php if (
($_item instanceof \Magento\Sales\Api\Data\TrackUrlInterface) &&
($_item->getTrackUrl())
): ?>
<a href="<?= $block->escapeUrl($_item->getTrackUrl()) ?>"
target="_blank"
rel="noreferrer nofollow noopener"
>
<?= $block->escapeHtml($_item->getNumber()) ?>
</a>
<?php else: ?>
<?= $block->escapeHtml($_item->getNumber()) ?>
<?php endif;?>
</td>
</tr>
<?php endforeach ?>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"magento/module-robots": "100.2.0-dev",
"magento/module-rss": "100.2.0-dev",
"magento/module-rule": "100.2.0-dev",
"magento/module-sales": "100.2.0-dev",
"magento/module-sales": "100.3.0-dev",
"magento/module-sales-inventory": "100.2.0-dev",
"magento/module-sales-rule": "100.2.0-dev",
"magento/module-sales-sequence": "100.2.0-dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ public function testGetList()
$filter3 = $filterBuilder->setField(ShipmentTrackInterface::TRACK_NUMBER)
->setValue('track number 4')
->create();
$filter4 = $filterBuilder->setField(ShipmentTrackInterface::CARRIER_CODE)
->setValue('carrier code 5')
$filter4 = $filterBuilder->setField(ShipmentTrackInterface::TRACK_URL)
->setValue('track url 5')
->create();
$filter5 = $filterBuilder->setField(ShipmentTrackInterface::QTY)
$filter5 = $filterBuilder->setField(ShipmentTrackInterface::CARRIER_CODE)
->setValue('carrier code 6')
->create();
$filter6 = $filterBuilder->setField(ShipmentTrackInterface::QTY)
->setConditionType('lt')
->setValue(5)
->create();
$filter6 = $filterBuilder->setField(ShipmentTrackInterface::WEIGHT)
$filter7 = $filterBuilder->setField(ShipmentTrackInterface::WEIGHT)
->setValue(1)
->create();

Expand All @@ -63,9 +66,9 @@ public function testGetList()
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class);

$searchCriteriaBuilder->addFilters([$filter1, $filter2, $filter3, $filter4]);
$searchCriteriaBuilder->addFilters([$filter5]);
$searchCriteriaBuilder->addFilters([$filter1, $filter2, $filter3, $filter4, $filter5]);
$searchCriteriaBuilder->addFilters([$filter6]);
$searchCriteriaBuilder->addFilters([$filter7]);
$searchCriteriaBuilder->setSortOrders([$sortOrder]);

$searchCriteriaBuilder->setPageSize(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'title' => 'title 1',
'carrier_code' => 'carrier code 1',
'track_number' => 'track number 1',
'track_url' => 'track url 1',
'description' => 'description 1',
'qty' => 1,
'weight' => 1,
Expand All @@ -46,6 +47,7 @@
'title' => 'title 2',
'carrier_code' => 'carrier code 2',
'track_number' => 'track number 2',
'track_url' => 'track url 3',
'description' => 'description 2',
'qty' => 2,
'weight' => 1,
Expand All @@ -54,6 +56,7 @@
'title' => 'title 3',
'carrier_code' => 'carrier code 3',
'track_number' => 'track number 3',
'track_url' => 'track url 3',
'description' => 'description 3',
'qty' => 3,
'weight' => 1,
Expand All @@ -62,6 +65,7 @@
'title' => 'title 4',
'carrier_code' => 'carrier code 4',
'track_number' => 'track number 4',
'track_url' => 'track url 4',
'description' => 'description 4',
'qty' => 4,
'weight' => 1,
Expand All @@ -70,6 +74,7 @@
'title' => 'title 5',
'carrier_code' => 'carrier code 5',
'track_number' => 'track number 5',
'track_url' => 'track url 5',
'description' => 'description 5',
'qty' => 5,
'weight' => 2,
Expand Down