Skip to content

MAGESHIP-21-develop Add track_url to DB & API and send via Customer S… #10977

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 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @api
* @since 100.1.2
*/
interface ShipmentTrackCreationInterface extends TrackInterface, ExtensibleDataInterface
interface ShipmentTrackCreationInterface extends TrackInterface, TrackUrlInterface, ExtensibleDataInterface
{
/**
* Retrieve existing extension attributes object or create a new one.
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Sales/Api/Data/ShipmentTrackInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @api
* @since 100.0.2
*/
interface ShipmentTrackInterface extends TrackInterface, ExtensibleDataInterface
interface ShipmentTrackInterface extends TrackInterface, TrackUrlInterface, ExtensibleDataInterface
{
/**#@+
* Constants for keys of data array. Identical to the name of the getter in snake case.
Expand Down
36 changes: 36 additions & 0 deletions app/code/Magento/Sales/Api/Data/TrackUrlInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sales\Api\Data;

/**
* Shipment Track URL Creation interface.
*
* @api
*/
interface TrackUrlInterface
{
/**#@+
* Constants for keys of data array. Identical to the name of the getter in snake case.
*/
/*
* Track URL.
*/
const TRACK_URL = 'track_url';
/**
* 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();
}
18 changes: 18 additions & 0 deletions app/code/Magento/Sales/Model/Order/Shipment/Track.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,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 +380,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/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 @@ -160,7 +160,7 @@
"magento/module-robots": "100.3.0-dev",
"magento/module-rss": "100.3.0-dev",
"magento/module-rule": "100.3.0-dev",
"magento/module-sales": "100.3.0-dev",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not needed, it will be automatically set by the packaging tool

"magento/module-sales": "100.3.1-dev",
"magento/module-sales-inventory": "100.3.0-dev",
"magento/module-sales-rule": "100.3.0-dev",
"magento/module-sales-sequence": "100.3.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