Exemplo n.º 1
0
 public static function getInstance(OrderedItem $item, ProductFile $file)
 {
     $instance = $item->getRelatedRecordSet('OrderedFile', select(eq('OrderedFile.productFileID', $file->getID())))->shift();
     if (!$instance) {
         $instance = self::getNewInstance($item, $file);
     }
     return $instance;
 }
Exemplo n.º 2
0
 public function testDeleteFileGroupWithFiles()
 {
     $group = ProductFileGroup::getNewInstance($this->product);
     $group->setNextPosition();
     $group->setValueByLang('name', 'en', 'TEST_GROUP');
     $group->save();
     $file = ClassLoader::getRealPath('cache.') . 'blabla';
     file_put_contents($file, 'asdsad');
     $productFile = ProductFile::getNewInstance($this->product, $file, 'movedFile.txt');
     $productFile->productFileGroup->set($group);
     $productFile->save();
     $productFilePath = $productFile->getPath();
     $group->delete();
     try {
         $productFile->reload();
         $this->fail();
     } catch (Exception $e) {
         $this->pass();
     }
     $this->assertFalse(is_file($productFilePath));
     unlink($file);
 }
Exemplo n.º 3
0
 /**
  * @return ARSet
  */
 public function getFiles()
 {
     ClassLoader::import('application.model.product.ProductFile');
     return ProductFile::getFilesByProduct($this);
 }
Exemplo n.º 4
0
 public function getFiles($loadReferencedRecords = false)
 {
     return ProductFile::getRecordSet($this->getFilesFilter(), $loadReferencedRecords);
 }
Exemplo n.º 5
0
 private function loadDownloadableItems(ARSelectFilter $f)
 {
     ClassLoader::import('application.model.product.ProductFile');
     return ProductFile::getOrderFiles($f);
 }
Exemplo n.º 6
0
 public function testMergeGroupsWithFIlters()
 {
     // create groups
     $productGroup = array();
     foreach (range(1, 3) as $i) {
         $productGroup[$i] = ProductFileGroup::getNewInstance($this->product);
         $productGroup[$i]->save();
     }
     // create files
     $productFile = array();
     $productFiles = array();
     $dir = ClassLoader::getRealPath('cache') . '/';
     foreach (range(1, 2) as $i) {
         file_put_contents($productFiles[$i] = $dir . md5($i), "file {$i}");
         $productFile[$i] = ProductFile::getNewInstance($this->product, $productFiles[$i], "test_file_{$i}.txt");
         $productFile[$i]->save();
     }
     $productFile[1]->productFileGroup->set($productGroup[2]);
     $productFile[1]->save();
     $this->assertEqual($this->product->getFileGroups()->getTotalRecordCount(), 3);
     $this->assertEqual($this->product->getFiles()->getTotalRecordCount(), 2);
     $filesMergedWithGroups = $this->product->getFilesMergedWithGroupsArray();
     $this->assertEqual(count($filesMergedWithGroups), 4);
     // Check files without group
     $this->assertTrue(isset($filesMergedWithGroups[1]['ID']));
     $this->assertEqual($filesMergedWithGroups[1]['ID'], $productFile[2]->getID());
     $this->assertFalse(isset($filesMergedWithGroups[1]['ProductFileGroup']['ID']));
     // Check first group
     $this->assertFalse(isset($filesMergedWithGroups[2]['ID']));
     $this->assertTrue(isset($filesMergedWithGroups[2]['ProductFileGroup']['ID']));
     $this->assertEqual($filesMergedWithGroups[2]['ProductFileGroup']['ID'], $productGroup[1]->getID());
     // Check second group
     $this->assertTrue(isset($filesMergedWithGroups[3]['ID']));
     $this->assertEqual($filesMergedWithGroups[3]['ID'], $productFile[1]->getID());
     $this->assertTrue(isset($filesMergedWithGroups[3]['ProductFileGroup']['ID']));
     $this->assertEqual($filesMergedWithGroups[3]['ProductFileGroup']['ID'], $productGroup[2]->getID());
     // Check second group
     $this->assertFalse(isset($filesMergedWithGroups[4]['ID']));
     $this->assertTrue(isset($filesMergedWithGroups[4]['ProductFileGroup']['ID']));
     $this->assertEqual($filesMergedWithGroups[4]['ProductFileGroup']['ID'], $productGroup[3]->getID());
     foreach ($productFiles as $fileName) {
         unlink($fileName);
     }
     foreach ($productFile as $file) {
         $file->delete();
     }
 }
Exemplo n.º 7
0
 /**
  *	@role login
  */
 public function completed()
 {
     if ($this->request->isValueSet('id')) {
         return new ActionRedirectResponse('checkout', 'completeExternal', array('id' => $this->request->get('id')));
     }
     $order = CustomerOrder::getInstanceByID((int) $this->session->get('completedOrderID'), CustomerOrder::LOAD_DATA);
     $order->loadAll();
     $response = new ActionResponse();
     $response->set('order', $order->toArray());
     $response->set('url', $this->router->createUrl(array('controller' => 'user', 'action' => 'viewOrder', 'id' => $this->session->get('completedOrderID')), true));
     if (!$order->isPaid->get()) {
         $transactions = $order->getTransactions()->toArray();
         $response->set('transactions', $transactions);
     } else {
         $response->set('files', ProductFile::getOrderFiles(select(eq('CustomerOrder.ID', $order->getID()))));
     }
     return $response;
 }
Exemplo n.º 8
0
 public function testChangeUploadedFile()
 {
     $productFile = ProductFile::getNewInstance($this->product, $this->tmpFilePath, 'some_file.txt');
     $productFile->save();
     $this->assertEqual(file_get_contents($productFile->getPath()), $this->fileBody);
     $reuploadedFile = ClassLoader::getRealPath('cache.') . 'reuploaded_file.txt';
     file_put_contents($reuploadedFile, $reuploadedFileBody = 'Reupload file');
     $productFile->storeFile($reuploadedFile, 'some_file.txt');
     $productFile->save();
     $this->assertEqual(file_get_contents($productFile->getPath()), $reuploadedFileBody);
     unlink($reuploadedFile);
     $productFile->delete();
 }
Exemplo n.º 9
0
 /**
  * @role update
  */
 public function sort()
 {
     $target = $this->request->get('target');
     preg_match('/_(\\d+)$/', $target, $match);
     // Get group.
     foreach ($this->request->get($this->request->get('target'), array()) as $position => $key) {
         if (empty($key)) {
             continue;
         }
         $file = ProductFile::getInstanceByID((int) $key);
         $file->position->set((int) $position);
         if (isset($match[1])) {
             $file->productFileGroup->set(ProductFileGroup::getInstanceByID((int) $match[1]));
         } else {
             $file->productFileGroup->setNull();
         }
         $file->save();
     }
     return new JSONResponse(false, 'success');
 }
Exemplo n.º 10
0
    public function product_show($slug)
    {
        $output = '';
        $product = Product::findBySlug($slug);
        $images = ProductImage::findByProduct($slug);
        $variants = ProductVariant::findByProduct($slug);
        $files = ProductFile::findByProduct($slug);
        $videos = ProductVideo::findByProduct($slug);
        $related_products = $this->products_related($slug);
        if ($product) {
            $output = '<div id="product_images">';
            if ($images) {
                foreach ($images as $image) {
                    $output .= '<img src="/public/ecommerce/images/products/' . $image->filename . '" />';
                }
            }
            if ($variants) {
                foreach ($variants as $variant) {
                    $description = '';
                    if ($variant->description) {
                        $description = $variant->description . '<br />';
                    }
                    $output .= '
					<form class="cart_form" action="/products/cart" method="post">
						<input type="hidden" name="variant_id" value="' . $variant->id . '" />
						<label>' . str_replace('Default', '', $variant->title) . '<br />' . $description . '</label>';
                    if ($variant->price > 0) {
                        $output .= '<span class="price">$' . number_format($variant->price, 2) . '</span> <input type="hidden" name="quantity" value="1" size="2" />
							<input type="submit" name="submit" value="Add to Cart" />';
                    }
                    $output .= '</form>';
                }
            }
            if ($files) {
                $output .= '<div id="files"><h3>Files</h3><ul>';
                foreach ($files as $file) {
                    $output .= '<li><a href="' . $file->filename . '" rel="external">' . $file->title . '</a></li>';
                }
                $output .= '</ul></div>';
            }
            if ($videos) {
                $output .= '<div id="videos"><h3>Videos</h3><ul>';
                foreach ($videos as $video) {
                    $output .= '<li><a href="' . $video->filename . '" rel="shadowbox">' . $video->title . '</a></li>';
                }
                $output .= '</ul></div>';
            }
            $output .= '</div>';
            $output .= $product->description;
            if ($related_products) {
                $output .= '<br clear="all"><h3>Related Products</h3>';
                $output .= $this->products_related($slug);
            }
        }
        return $output;
    }