Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Duplicating File Attachments module

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 05-08-2015, 03:29 AM
 
xgarb xgarb is offline
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 262
 

Default Duplicating File Attachments module

Client wants two extra tabs for each product. A file downloads area and a case studies area.

I'm 98% there. I've duplicated the file attachments module and re-coded as necessary to create new fields in the database and files in the file system.

I have a problem though.. The code...

Code:
/** * Get attachment * * @return \XLite\Module\Client\CaseStudies\Model\Product\Casestudy */ protected function getCasestudy() { return \XLite\Core\Database::getRepo('XLite\Module\Client\CaseStudies\Model\Product\Casestudy') ->find(\XLite\Core\Request::getInstance()->objectId); }
doesn't seem to be returning anything when I upload a file.. or at least I'm getting the error..
Call to a member function getProduct() on a non-object
in
$path = parent::getStoreFileSystemRoot() . $this->getCasestudy()->getProduct()->getProductId() . LC_DS;

If I hard code the path it works but the attachment_id field in the database isn't filled in and therefor the list of attachments doesn't work properly until I put in the missing value manually.

Any ideas?

I was wondering if the Monthly Support subscription would enable me to get little things like this sorted? I have one big project at the moment on x5 and often little questions.
__________________
Core version: 5.3.xx
PHP: 5.6
MySQL: 5.5.50-cll
Web server: Apache
Reply With Quote
  #2  
Old 05-08-2015, 03:39 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Duplicating File Attachments module

Could you please show us a full error message?

It says "Call to a member function getProduct() on a non-object", but I do not see what object getProduct() method is called upon?

This code would help understand what is wrong.
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
  #3  
Old 05-08-2015, 04:12 AM
 
xgarb xgarb is offline
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 262
 

Default Re: Duplicating File Attachments module

Call to a member function getProduct() on a non-object in /home/client/public_html/xcart5_2/var/run/classes/XLite/Module/client/CaseStudies/Model/Product/Casestudy/Storage.php on line 95


line 95 is...

$path = parent::getStoreFileSystemRoot() . $this->getCasestudy()->getProduct()->getProductId() . LC_DS;
__________________
Core version: 5.3.xx
PHP: 5.6
MySQL: 5.5.50-cll
Web server: Apache
Reply With Quote
  #4  
Old 05-10-2015, 11:20 PM
 
xgarb xgarb is offline
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 262
 

Default Re: Duplicating File Attachments module

Some more information that might help...

In the module (File Attachments) that I'm attempting to duplicate there's this code to upload a file...

Code:
<div class="add-file"> <widget class="XLite\View\Button\FileSelector" label="Add file" object="product" objectId="{product.getProductId()}" fileObject="attachments" /> </div>

one of the changes in the module code I've made is to change the fileObject...

Code:
<div class="add-file"> <widget class="XLite\View\Button\FileSelector" label="Add file" object="product" objectId="{product.getProductId()}" fileObject="casestudies" /> </div>

Can you explain what this fileObject is a little and what the process is that uploading a file starts. I want to make sure I'm dealing with this correctly in my module.
__________________
Core version: 5.3.xx
PHP: 5.6
MySQL: 5.5.50-cll
Web server: Apache
Reply With Quote
  #5  
Old 05-12-2015, 06:32 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Duplicating File Attachments module

@xgarb, generally speaking the problem is caused by the fact that the $this->getCasestudy()->getProduct() construction does not return a product object. You need to find out why and it will be a key to how to fix the problem.

If you grep by 'fileObject' substring through X-Cart code, you will see that it is used for definition of POST variable where we should look for the actual file uploaded.
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
  #6  
Old 05-14-2015, 11:17 AM
 
xgarb xgarb is offline
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 262
 

Default Re: Duplicating File Attachments module

In the following...

Code:
/** * Get storage * * @return \XLite\Module\CDev\FileAttachments\Model\Product\Attachment\Storage */ public function getStorage() { if (!$this->storage) { $this->setStorage(new \XLite\Module\CDev\FileAttachments\Model\Product\Attachment\Storage); $this->storage->setAttachment($this); } return $this->storage; }

Am I right in thinking that the code creates a storage object and then adds the uploaded file to it?

I can't find setAttachment anywhere in the x5 source code to see what it's doing.
__________________
Core version: 5.3.xx
PHP: 5.6
MySQL: 5.5.50-cll
Web server: Apache
Reply With Quote
  #7  
Old 05-28-2015, 05:29 AM
 
xgarb xgarb is offline
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 262
 

Default Re: Duplicating File Attachments module

Any pointers?

Thanks,
Andrew
__________________
Core version: 5.3.xx
PHP: 5.6
MySQL: 5.5.50-cll
Web server: Apache
Reply With Quote
  #8  
Old 05-29-2015, 03:06 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Duplicating File Attachments module

Yes, you are right. This code creates a storage object and then links storage and attachment objects.
If you grep by "on setAttachment(" substring in the source code, you will see that the method is defined in the following files:

var/run/classes/XLite/Module/CDev/Egoods/Model/OrderItem/PrivateAttachment.php
var/run/classes/XLite/Module/CDev/FileAttachments/Model/Product/Attachment/StorageAbstract.php

Please let me know if my reply is any helpful, because I am not sure about that
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
  #9  
Old 06-08-2015, 06:34 AM
 
xgarb xgarb is offline
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 262
 

Default Re: Duplicating File Attachments module

Thanks. I found it and the module now works.

I hadn't realised that X-cart 5 moves and creates methods in the run directory that don't exist in the normal xlite directory.
__________________
Core version: 5.3.xx
PHP: 5.6
MySQL: 5.5.50-cll
Web server: Apache
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 02:23 PM.

   

 
X-Cart forums © 2001-2020