Skip to content

Commit

Permalink
Merge pull request #5 from sndsabin/pimcore63
Browse files Browse the repository at this point in the history
support for pimcore version > 5.6
  • Loading branch information
sndsabin committed Jan 20, 2020
2 parents fb2057b + c574150 commit e223c47
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 85 deletions.
1 change: 1 addition & 0 deletions Controller/ObjectsWithCsvController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down
Binary file modified Docs/images/data-type.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Docs/images/form.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Model/DataObject/ClassDefinition/Data/ObjectsWithCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
18 changes: 17 additions & 1 deletion ObjectsWithCsvBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion Resources/public/img/csv-import.svg

This file was deleted.

7 changes: 7 additions & 0 deletions Resources/public/img/upload.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 55 additions & 63 deletions Resources/public/js/pimcore/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,85 +24,77 @@ 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 + '<br /><hr />' +
'<span style="font-size:12px">'
+ '<b>' + errorText + '</b>' +
"</span>";

}
if (stack) {
stack = str_replace("#", "<br>#", stack);
var htmlValue = '<a href="#">' + t("details") + '</a>';
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 =
'<pre style="font-size:11px;word-wrap: break-word;">'
+ detailText +
"</pre>";
}

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 + '<br>' + 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();
}
}]
});
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;
};
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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";
}


Expand Down
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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({
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Resources/translations/admin.en.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
objectsWithCsv: 'Objects With CSV Upload'
objectsWithCsv: 'Many To Many Object Relation With CSV Upload'
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"pimcore/core-version": ">=5.0 <5.6"
"pimcore/pimcore": ">=5.6.0"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit e223c47

Please sign in to comment.