Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » How to import XML data in a dataobject?

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 1527 Views
  • neglostyti
    Avatar
    Community Member
    5 Posts

    Re: How to import XML data in a dataobject? Link to this post

    Thanks, kpower, it was really helpful. Now I can 'upload' images, but there is another problem - after I upload many items, on admin panel I can only see few of them. And their status are deleted(or smth like that).

    I checked few times data on database - records are there(only in catalog_live, product_live and sitetree_live tables), ParendID is correct.

    I was played with doPublish() and ->Status = 'Publish' but it doesn't helped.

    My code is here: http://pastebin.com/CMjA6epG

    How it looks in admin:
    http://img3.imageshack.us/img3/537/adminmenu.png

    What was inserted:
    http://img220.imageshack.us/img220/4316/datapv.png

    As you can see, I can not see products under the `Spodnie`;

    In total, there is about 2500 products. If I add all of them, then I can not see products at all, even full tree up to the products.

    The code doesn't look very nice, I know, but this migration i will use only once.

    Any ideas? Thank you for any help.

  • kpower
    Avatar
    Community Member
    7 Posts

    Re: How to import XML data in a dataobject? Link to this post

    Sorry, I can't see any image by going through the links you posted. Also showing the whole code doesn't help. In future, please isolate the code in which you think the problem actually resides

    Considering the following code fragment:

    $do = new Product();
    $do->ParentID = $pid;

    $img = new Image();
    $img->setFilename(ASSETS_DIR . '/images/' . $image . '.jpg');
    $img->Title = $data['name'];
    $imgID = $img->write();
    $img->CMSThumbnail();
    $img->updateFilesystem();

    $imgStr = 'Photo' . ($i+1) . 'ID';
    $do->{$imgStr} = $imgID;

    I'm not sure what this "Product" is, but I guess it's your DataObject. If that is, can you let us know what you expected to do with the last two statements? Were you perhaps trying to add the created Image to the Product, as Product has one-to-many relationship with Image ?

    1527 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.