Exemplo n.º 1
0
 /**
  * Common handler for product attachments
  *
  * @param string $methodToLoad Method to use for getting images
  * @param array  $paramsToLoad Parameters to use in attachment getter method
  *
  * @return void
  */
 protected function doActionSelectProductAttachments($methodToLoad, array $paramsToLoad)
 {
     $productId = intval(\XLite\Core\Request::getInstance()->objectId);
     $product = \XLite\Core\Database::getRepo('XLite\\Model\\Product')->find($productId);
     if (isset($product)) {
         $attachment = new \XLite\Module\CDev\FileAttachments\Model\Product\Attachment();
         $attachment->setProduct($product);
         if (call_user_func_array(array($attachment->getStorage(), $methodToLoad), $paramsToLoad)) {
             $found = false;
             foreach ($attachment->getStorage()->getDuplicates() as $duplicate) {
                 if ($duplicate instanceof \XLite\Module\CDev\FileAttachments\Model\Product\Attachment\Storage && $duplicate->getAttachment()->getProduct()->getProductId() == $product->getProductId()) {
                     $found = true;
                     break;
                 }
             }
             if ($found) {
                 \XLite\Core\TopMessage::addError('The same file can not be assigned to one product');
             } else {
                 $product->addAttachments($attachment);
                 \XLite\Core\Database::getEM()->persist($attachment);
                 \XLite\Core\Database::getEM()->flush();
                 \XLite\Core\TopMessage::addInfo('The attachment has been added successfully');
             }
         } elseif ('extension' == $attachment->getStorage()->getLoadError()) {
             // Forbid extension
             \XLite\Core\TopMessage::addError('Failed to add the attachment. The file download is forbidden');
         } else {
             \XLite\Core\TopMessage::addError('Failed to add the attachment');
         }
     } else {
         \XLite\Core\TopMessage::addError('Failed to add the attachment');
     }
 }
Exemplo n.º 2
0
 public function testGetStorage()
 {
     \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_FILES . 'attachments');
     $attach = new \XLite\Module\CDev\FileAttachments\Model\Product\Attachment();
     $this->assertInstanceOf('XLite\\Module\\CDev\\FileAttachments\\Model\\Product\\Attachment\\Storage', $attach->getStorage(), 'check class');
     $this->assertEquals($attach, $attach->getStorage()->getAttachment(), 'check attachment');
 }