Skip to content

Commit 6b0ec0b

Browse files
committed
add admin UI optimizations
1 parent 0c948c0 commit 6b0ec0b

File tree

10 files changed

+165
-2
lines changed

10 files changed

+165
-2
lines changed

Api/Data/ParameterDefinitionInterface.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public function setId(string $id);
2525
*/
2626
public function setName(string $label);
2727

28+
/**
29+
* @param string $unit
30+
* @return void
31+
*/
32+
public function setUnit(?string $unit);
33+
2834
/**
2935
* @param string $type
3036
* @return void
@@ -64,6 +70,11 @@ public function getName(): ?string;
6470
*/
6571
public function getType(): ?string;
6672

73+
/**
74+
* @return string
75+
*/
76+
public function getUnit(): ?string;
77+
6778
/**
6879
* @return bool
6980
*/

Block/Adminhtml/Offer/BackButton.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Macopedia\Allegro\Block\Adminhtml\Offer;
4+
5+
use Magento\Catalog\Api\Data\ProductInterface;
6+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
7+
8+
/**
9+
* Back button configuration provider
10+
*/
11+
class BackButton implements ButtonProviderInterface
12+
{
13+
/**
14+
* Url Builder
15+
*
16+
* @var \Magento\Framework\UrlInterface
17+
*/
18+
protected $urlBuilder;
19+
20+
/**
21+
* Registry
22+
*
23+
* @var \Magento\Framework\Registry
24+
*/
25+
protected $registry;
26+
27+
/**
28+
* Constructor
29+
*
30+
* @param \Magento\Backend\Block\Widget\Context $context
31+
* @param \Magento\Framework\Registry $registry
32+
*/
33+
public function __construct(
34+
\Magento\Backend\Block\Widget\Context $context,
35+
\Magento\Framework\Registry $registry
36+
) {
37+
$this->urlBuilder = $context->getUrlBuilder();
38+
$this->registry = $registry;
39+
}
40+
41+
/**
42+
* Return button attributes array
43+
*/
44+
public function getButtonData()
45+
{
46+
return [
47+
'label' => __('Back'),
48+
'class' => 'action- scalable back',
49+
'on_click' => $this->getOnclick(),
50+
'sort_order' => 10,
51+
];
52+
}
53+
54+
/**
55+
* @return string
56+
*/
57+
protected function getOnClick()
58+
{
59+
return sprintf(
60+
"location.href = '%s';",
61+
$this->urlBuilder->getUrl('catalog/product/edit', ['id' => $this->getProduct()->getId()])
62+
);
63+
}
64+
65+
/**
66+
* @return ProductInterface
67+
*/
68+
private function getProduct()
69+
{
70+
return $this->registry->registry('product');
71+
}
72+
}

Block/Adminhtml/Offer/SaveButton.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public function getButtonData()
4545
return [
4646
'label' => __('Save'),
4747
'class' => 'save primary',
48-
'on_click' => "location.href = '" . $this->urlBuilder->getUrl('allegro/offer/save') . "';",
4948
'data_attribute' => [
5049
'mage-init' => ['button' => ['event' => 'save']],
5150
'form-role' => 'save',
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © Macopedia. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Macopedia\Allegro\Model\Config\CommentText;
8+
9+
use Magento\Config\Model\Config\CommentInterface;
10+
11+
class CallbackUrl implements CommentInterface
12+
{
13+
/**
14+
* @var \Magento\Backend\Model\UrlInterface
15+
*/
16+
protected $url;
17+
18+
/**
19+
* CallbackUrl constructor.
20+
* @param \Magento\Backend\Model\UrlInterface $url
21+
*/
22+
public function __construct(\Magento\Backend\Model\UrlInterface $url)
23+
{
24+
$this->url = $url;
25+
}
26+
27+
public function getCommentText($elementValue)
28+
{
29+
$this->url->setNoSecret(true);
30+
return $this->url->getUrl('allegro/system/authenticate');
31+
}
32+
}

Model/Data/ParameterDefinition.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ParameterDefinition extends DataObject implements ParameterDefinitionInter
1515

1616
const ID_FIELD_NAME = 'id';
1717
const NAME_FIELD_NAME = 'name';
18+
const UNIT_FIELD_NAME = 'unit';
1819
const REQUIRED_FIELD_NAME = 'required';
1920
const VALUES_COUNT_FIELD_NAME = 'values_count';
2021
const TYPE_FIELD_NAME = 'type';
@@ -66,6 +67,15 @@ public function setType(string $type)
6667
$this->setData(self::TYPE_FIELD_NAME, $type);
6768
}
6869

70+
/**
71+
* @param string $type
72+
* @return void
73+
*/
74+
public function setUnit(?string $type)
75+
{
76+
$this->setData(self::UNIT_FIELD_NAME, $type);
77+
}
78+
6979
/**
7080
* @param bool $required
7181
* @return void
@@ -117,6 +127,14 @@ public function getType(): ?string
117127
return $this->getData(self::TYPE_FIELD_NAME);
118128
}
119129

130+
/**
131+
* @return string
132+
*/
133+
public function getUnit(): ?string
134+
{
135+
return $this->getData(self::UNIT_FIELD_NAME);
136+
}
137+
120138
/**
121139
* @return bool
122140
*/
@@ -199,6 +217,9 @@ public function setRawData(array $rawData)
199217
if (isset($rawData['type'])) {
200218
$this->setType($rawData['type']);
201219
}
220+
if (isset($rawData['unit'])) {
221+
$this->setUnit($rawData['unit']);
222+
}
202223

203224
$this->setRequired($rawData['required'] ?? false);
204225
$this->setRestrictions($this->mapRestrictionsData($rawData['restrictions'] ?? []));

Ui/AllegroOffer/Form/CreateDataProvider.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ public function __construct(
6969
$this->config = $config;
7070
}
7171

72+
/**
73+
* @param Product $product
74+
* @return string
75+
*/
76+
protected function getAllegroImage(Product $product)
77+
{
78+
if ($product->getAllegroImage() && $product->getAllegroImage() !== 'no_selection') {
79+
return $product->getAllegroImage();
80+
}
81+
82+
return $product->getImage();
83+
}
84+
7285
/**
7386
* Get data
7487
*
@@ -86,7 +99,7 @@ public function getData()
8699
$product = $this->registry->registry('product');
87100
$stock = $this->getSalableQuantityDataBySku->execute($product->getSku());
88101
$images = $product->getMediaGalleryImages()->toArray();
89-
$allegroImage = $product->getAllegroImage();
102+
$allegroImage = $this->getAllegroImage($product);
90103
foreach ($images['items'] as $key => $image) {
91104
if ($image['file'] !== $allegroImage) {
92105
unset($images['items'][$key]);

etc/adminhtml/system.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,24 @@
2222
<depends>
2323
<field id="sandbox">0</field>
2424
</depends>
25+
<comment><![CDATA[
26+
Register App in <a target="_blank" href="https://apps.developer.allegro.pl/">https://apps.developer.allegro.pl/</a>
27+
]]></comment>
2528
</field>
2629
<field id="sandbox_authentication_url" translate="label comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
2730
<label>Sandbox Authentication Url</label>
2831
<depends>
2932
<field id="sandbox">1</field>
3033
</depends>
34+
<comment><![CDATA[
35+
Register App in <a target="_blank" href="https://apps.developer.allegro.pl.allegrosandbox.pl/">https://apps.developer.allegro.pl.allegrosandbox.pl/</a>
36+
]]></comment>
37+
</field>
38+
<field id="callback_url" translate="label comment" type="label" sortOrder="35" showInDefault="1" showInWebsite="1" showInStore="1">
39+
<label>Use following callback</label>
40+
<comment>
41+
<model>\Macopedia\Allegro\Model\Config\CommentText\CallbackUrl</model>
42+
</comment>
3143
</field>
3244
</group>
3345
<group id="credentials" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="20" translate="label">

view/adminhtml/ui_component/allegro_offer_form_create.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
<settings>
1919
<buttons>
20+
<button name="back" class="Macopedia\Allegro\Block\Adminhtml\Offer\BackButton"/>
2021
<button name="save" class="Macopedia\Allegro\Block\Adminhtml\Offer\SaveButton"/>
2122
</buttons>
2223
<namespace>allegro_offer_form_create</namespace>

view/adminhtml/ui_component/allegro_offer_form_edit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
<settings>
1919
<buttons>
20+
<button name="back" class="Macopedia\Allegro\Block\Adminhtml\Offer\BackButton"/>
2021
<button name="save" class="Macopedia\Allegro\Block\Adminhtml\Offer\SaveButton"/>
2122
<button name="publish" class="Macopedia\Allegro\Block\Adminhtml\Offer\PublishButton"/>
2223
<button name="end" class="Macopedia\Allegro\Block\Adminhtml\Offer\EndButton"/>

view/adminhtml/web/template/allegro_offer/form/field/attributes-table.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<div>
2222
<label data-bind="attr: { for: $parent.uid + definition.id }">
2323
<span data-bind="text: definition.name"></span>
24+
<span if="unit" data-bind="text: ' ( ' + unit + ' ) '"></span>
2425
</label>
2526
</div>
2627
<div>

0 commit comments

Comments
 (0)