diff --git a/Controller/ObjectsWithCsvController.php b/Controller/ObjectsWithCsvController.php index 120714a..9aaf7c6 100755 --- a/Controller/ObjectsWithCsvController.php +++ b/Controller/ObjectsWithCsvController.php @@ -127,6 +127,7 @@ protected function bakeSearchData($csvData, $searchValues) protected function retrieveDataObjects($allowedClasses, $key, $searchValues) { $dataObjectsArray = []; + $retrievedObjectsIdentifiers = []; foreach ($allowedClasses as $class) { if (class_exists($className = "\\Pimcore\\Model\\DataObject\\" . ucfirst($class))) { diff --git a/Docs/images/data-type.png b/Docs/images/data-type.png index 34938ea..ff4803c 100644 Binary files a/Docs/images/data-type.png and b/Docs/images/data-type.png differ diff --git a/Docs/images/form.png b/Docs/images/form.png index be67c9e..e15d52b 100644 Binary files a/Docs/images/form.png and b/Docs/images/form.png differ diff --git a/Model/DataObject/ClassDefinition/Data/ObjectsWithCsv.php b/Model/DataObject/ClassDefinition/Data/ObjectsWithCsv.php index 394279d..1b72c02 100755 --- a/Model/DataObject/ClassDefinition/Data/ObjectsWithCsv.php +++ b/Model/DataObject/ClassDefinition/Data/ObjectsWithCsv.php @@ -8,9 +8,9 @@ namespace ObjectsWithCsvBundle\Model\DataObject\ClassDefinition\Data; -use Pimcore\Model\DataObject\ClassDefinition\Data\Objects; +use Pimcore\Model\DataObject\ClassDefinition\Data\ManyToManyObjectRelation; -class ObjectsWithCsv extends Objects +class ObjectsWithCsv extends ManyToManyObjectRelation { public $fieldtype = 'objectsWithCsv'; } \ No newline at end of file diff --git a/ObjectsWithCsvBundle.php b/ObjectsWithCsvBundle.php index c5fe51d..d0f90a8 100755 --- a/ObjectsWithCsvBundle.php +++ b/ObjectsWithCsvBundle.php @@ -28,6 +28,22 @@ public function getDescription() */ public function getVersion() { - return '1.0.2'; + return '2.0.0'; + } + + /** + * Returns the bundle name that this bundle overrides. + * + * Despite its name, this method does not imply any parent/child relationship + * between the bundles, just a way to extend and override an existing + * bundle. + * + * @return string The Bundle name it overrides or null if no parent + * + * @deprecated This method is deprecated as of 3.4 and will be removed in 4.0. + */ + public function getParent() + { + // TODO: Implement getParent() method. } } diff --git a/README.md b/README.md index dadf7e7..7049a5e 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,15 @@ Facilitates user to upload csv file for bulk attaching to objects datatype using csv upload functionality. -![DataObject Edit Form](/Docs/images/form.png "Dataobject Edit Form") +![DataObject Edit Form](Docs/images/form.png "Dataobject Edit Form") -![CSV Upload](/Docs/images/upload-modal.png "CSV Upload") +![CSV Upload](Docs/images/upload-modal.png "CSV Upload") # Installation ## Prerequisite -Requires **pimcore > 5.0** and **pimcore < 5.6** +Requires **pimcore > 5.6** ### Step 1 @@ -28,7 +28,7 @@ Requires **pimcore > 5.0** and **pimcore < 5.6** - Then `objectWithCsv` would be available in field selector under Relations (Add Data Component -> Relation -> objectsWithCsv) -![objectWithCsv](/Docs/images/data-type.png "objectWithCsv") +![objectWithCsv](Docs/images/data-type.png "objectWithCsv") # Sample CSV @@ -38,21 +38,21 @@ Multiple products are to be attached to category in pimcore. **Product** Dataobject -![product-dataobject](/Docs/images/product.png "Product DataObject") +![product-dataobject](Docs/images/product.png "Product DataObject") where `sku` is the unique identifier to identify the `product` objects. **Category** Dataobject -![product-dataobject](/Docs/images/category.png "Category DataObject") +![product-dataobject](Docs/images/category.png "Category DataObject") and the Edit form for Category Objects -![DataObject Edit Form](/Docs/images/form.png "Dataobject Edit Form") +![DataObject Edit Form](Docs/images/form.png "Dataobject Edit Form") -![CSV Upload](/Docs/images/upload-modal.png "CSV Upload") +![CSV Upload](Docs/images/upload-modal.png "CSV Upload") -So, In our case. the [sample csv](/Docs/csv/bulk-upload.csv "Sample CSV") be would be like the below : +So, In our case. the [sample csv](Docs/csv/bulk-upload.csv "Sample CSV") be would be like the below : ``` sku diff --git a/Resources/public/img/csv-import.svg b/Resources/public/img/csv-import.svg deleted file mode 100755 index 81ab806..0000000 --- a/Resources/public/img/csv-import.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/Resources/public/img/upload.svg b/Resources/public/img/upload.svg new file mode 100644 index 0000000..d9dda50 --- /dev/null +++ b/Resources/public/img/upload.svg @@ -0,0 +1,7 @@ + + + + + + diff --git a/Resources/public/js/pimcore/helpers.js b/Resources/public/js/pimcore/helpers.js index e63458f..8e9b460 100644 --- a/Resources/public/js/pimcore/helpers.js +++ b/Resources/public/js/pimcore/helpers.js @@ -24,80 +24,55 @@ pimcore.objectsWithCsv.helpers.listify = function (data, textTobeAttached = null return response }; -pimcore.objectsWithCsv.helpers.showPrettyMessage = function (type, title, text, errorText, stack, code) { +pimcore.objectsWithCsv.helpers.showPrettyMessage = function (type, title, text, errorText, detailText) { // types: info,error,success - if (errorText != null && errorText != undefined) { - if (t(errorText) != "~" + errorText + "~") { - errorText = t(errorText); - } - - text = text + '

' + - '' - + '' + errorText + '' + - ""; - - } - if (stack) { - stack = str_replace("#", "
#", stack); - var htmlValue = '' + t("details") + ''; - var detailedInfo = { - xtype: "displayfield", - readOnly: true, - value: htmlValue, - width: 300, - listeners: { - render: function (c) { - c.getEl().on('click', function () { - var detailedWindow = new Ext.Window({ - modal: true, - title: t('details'), - width: 1000, - height: 600, - html: stack, - autoScroll: true, - bodyStyle: "padding: 10px; background:#fff;", - buttonAlign: "center", - shadow: false, - closable: true, - buttons: [{ - text: t("OK"), - handler: function () { - detailedWindow.close(); - } - }] - }); - detailedWindow.show(); - }, c); - }.bind(this) - } - }; + if (detailText) { + detailText = + '
'
+            + detailText +
+            "
"; } - if (code) { - title = title + " " + code; - } var errWin = new Ext.Window({ modal: true, - iconCls: 'pimcore_icon_' + type, + iconCls: "pimcore_icon_" + type, title: title, - width: 600, - - layout: 'vbox', - items: [ - { - xtype: 'panel', - html: text, - width: '100%' - }, - detailedInfo - ], + width: 700, + maxHeight: 500, + html: text + '
' + errorText, autoScroll: true, - bodyStyle: "padding: 10px; background:#fff;", + bodyStyle: "padding: 10px;", buttonAlign: "center", shadow: false, closable: false, buttons: [{ - text: "OK", + text: t("details"), + hidden: !detailText, + handler: function () { + errWin.close(); + + var detailWindow = new Ext.Window({ + modal: true, + title: t('details'), + width: 1000, + height: '95%', + html: detailText, + autoScroll: true, + bodyStyle: "padding: 10px;", + buttonAlign: "center", + shadow: false, + closable: true, + buttons: [{ + text: t("OK"), + handler: function () { + detailWindow.close(); + } + }] + }); + detailWindow.show(); + } + }, { + text: t("OK"), handler: function () { errWin.close(); } @@ -105,4 +80,21 @@ pimcore.objectsWithCsv.helpers.showPrettyMessage = function (type, title, text, }); errWin.show(); +}; + +pimcore.objectsWithCsv.helpers.addCsrfTokenToUrl = function (url) { + + // only for /admin urls + if(url.indexOf('/admin') !== 0) { + return url; + } + + if (url.indexOf('?') === -1) { + url = url + "?"; + } else { + url = url + "&"; + } + url = url + 'csrfToken=' + pimcore.settings['csrfToken']; + + return url; }; \ No newline at end of file diff --git a/Resources/public/js/pimcore/objects/classes/data/objectsWithCsv.js b/Resources/public/js/pimcore/objects/classes/data/objectsWithCsv.js index be5c985..dfe42cb 100755 --- a/Resources/public/js/pimcore/objects/classes/data/objectsWithCsv.js +++ b/Resources/public/js/pimcore/objects/classes/data/objectsWithCsv.js @@ -1,5 +1,5 @@ pimcore.registerNS('pimcore.object.classes.data.objectsWithCsv'); -pimcore.object.classes.data.objectsWithCsv = Class.create(pimcore.object.classes.data.objects, { +pimcore.object.classes.data.objectsWithCsv = Class.create(pimcore.object.classes.data.manyToManyObjectRelation, { type: 'objectsWithCsv', initialize: function (treeNode, initData) { @@ -35,7 +35,7 @@ pimcore.object.classes.data.objectsWithCsv = Class.create(pimcore.object.classes * @returns {string} */ getIconClass: function () { - return "pimcore_icon_multihref"; + return "pimcore_icon_manyToManyObjectRelation"; } diff --git a/Resources/public/js/pimcore/objects/classes/tags/objectsWithCsv.js b/Resources/public/js/pimcore/objects/classes/tags/objectsWithCsv.js index 5877cc4..f1bac33 100755 --- a/Resources/public/js/pimcore/objects/classes/tags/objectsWithCsv.js +++ b/Resources/public/js/pimcore/objects/classes/tags/objectsWithCsv.js @@ -1,5 +1,5 @@ pimcore.registerNS('pimcore.object.tags.objectsWithCsv'); -pimcore.object.tags.objectsWithCsv = Class.create(pimcore.object.tags.objects, { +pimcore.object.tags.objectsWithCsv = Class.create(pimcore.object.tags.manyToManyObjectRelation, { type: "objectsWithCsv", getEditToolbarItems: function () { var toolbarItems = [ @@ -21,7 +21,7 @@ pimcore.object.tags.objectsWithCsv = Class.create(pimcore.object.tags.objects, { }, { xtype: "button", - icon: '/bundles/objectswithcsv/img/csv-import.svg', + icon: '/bundles/objectswithcsv/img/upload.svg', handler: function () { var objRef = this; var uploadWindowCompatible = new Ext.Window({ @@ -32,9 +32,7 @@ pimcore.object.tags.objectsWithCsv = Class.create(pimcore.object.tags.objects, { modal: true }); - var url = '/admin/objects-with-csv/parse'; - url = pimcore.helpers.addCsrfTokenToUrl(url); - + var url = pimcore.objectsWithCsv.helpers.addCsrfTokenToUrl('/admin/objects-with-csv/parse'); var allowedClass = ''; this.fieldConfig.classes.forEach(function (data) { diff --git a/Resources/translations/admin.en.yml b/Resources/translations/admin.en.yml index b6ca3e6..7b7b108 100644 --- a/Resources/translations/admin.en.yml +++ b/Resources/translations/admin.en.yml @@ -1 +1 @@ -objectsWithCsv: 'Objects With CSV Upload' \ No newline at end of file +objectsWithCsv: 'Many To Many Object Relation With CSV Upload' \ No newline at end of file diff --git a/composer.json b/composer.json index 1db6719..9509253 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "pimcore/core-version": ">=5.0 <5.6" + "pimcore/pimcore": ">=5.6.0" }, "autoload": { "psr-4": {