1 | <?php |
||
36 | class FileUploadObserver extends AbstractProductImportObserver |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * Process the observer's business logic. |
||
41 | * |
||
42 | * @return array The processed row |
||
43 | */ |
||
44 | protected function process() |
||
45 | { |
||
46 | |||
47 | // query whether or not, the image changed |
||
48 | if ($this->isParentImage($image = $this->getValue(ColumnKeys::IMAGE_PATH))) { |
||
49 | return; |
||
50 | } |
||
51 | |||
52 | // initialize the image path |
||
53 | $imagePath = $this->getValue(ColumnKeys::IMAGE_PATH); |
||
54 | |||
55 | // query whether or not we've to upload the image files |
||
56 | if ($this->hasCopyImages()) { |
||
57 | // upload the file and set the new image path |
||
58 | $imagePath = $this->uploadFile($image); |
||
59 | } |
||
60 | |||
61 | // temoprarily persist the image path |
||
62 | $this->setValue(ColumnKeys::IMAGE_PATH_NEW, $imagePath); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Upload's the file with the passed name to the Magento |
||
67 | * media directory. If the file already exists, the will |
||
68 | * be given a new name that will be returned. |
||
69 | * |
||
70 | * @param string $filename The name of the file to be uploaded |
||
71 | * |
||
72 | * @return string The name of the uploaded file |
||
73 | */ |
||
74 | protected function uploadFile($filename) |
||
78 | |||
79 | /** |
||
80 | * Return's the name of the created image. |
||
81 | * |
||
82 | * @return string The name of the created image |
||
83 | */ |
||
84 | protected function getParentImage() |
||
88 | |||
89 | /** |
||
90 | * Return's TRUE if the passed image is the parent one. |
||
91 | * |
||
92 | * @param string $image The imageD to check |
||
93 | * |
||
94 | * @return boolean TRUE if the passed image is the parent one |
||
95 | */ |
||
96 | protected function isParentImage($image) |
||
100 | |||
101 | /** |
||
102 | * Return's the flag to copy images or not. |
||
103 | * |
||
104 | * @return booleas The flag |
||
105 | */ |
||
106 | protected function hasCopyImages() |
||
110 | } |
||
111 |