X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Duplicating File Attachments module (https://forum.x-cart.com/showthread.php?t=72058)

xgarb 05-08-2015 03:29 AM

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.

tony_sologubov 05-08-2015 03:39 AM

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.

xgarb 05-08-2015 04:12 AM

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;

xgarb 05-10-2015 11:20 PM

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.

tony_sologubov 05-12-2015 06:32 AM

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.

xgarb 05-14-2015 11:17 AM

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.

xgarb 05-28-2015 05:29 AM

Re: Duplicating File Attachments module
 
Any pointers?

Thanks,
Andrew

tony_sologubov 05-29-2015 03:06 AM

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 :)

xgarb 06-08-2015 06:34 AM

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.


All times are GMT -8. The time now is 01:15 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.