Public Member Functions | |
getLinks ($product=null) | |
hasLinks ($product=null) | |
hasOptions ($product=null) | |
hasRequiredOptions ($product=null) | |
getLinkSelectionRequired ($product=null) | |
getSamples ($product=null) | |
hasSamples ($product=null) | |
save ($product=null) | |
prepareForCart (Varien_Object $buyRequest, $product=null) | |
getOrderOptions ($product=null) | |
beforeSave ($product=null) | |
getSearchableData ($product=null) | |
Public Attributes | |
const | TYPE_DOWNLOADABLE = 'downloadable' |
Definition at line 34 of file Type.php.
beforeSave | ( | $ | product = null |
) |
Setting flag if dowenloadable product can be or not in complex product based on link can be purchased separately or not
Mage_Catalog_Model_Product | $product |
Reimplemented from Mage_Catalog_Model_Product_Type_Abstract.
Definition at line 345 of file Type.php.
00346 { 00347 parent::beforeSave($product); 00348 00349 00350 if ($this->getLinkSelectionRequired($product)) { 00351 $this->getProduct($product)->setTypeHasOptions(true); 00352 $this->getProduct($product)->setTypeHasRequiredOptions(true); 00353 } else { 00354 $this->getProduct($product)->setTypeHasOptions(false); 00355 $this->getProduct($product)->setTypeHasRequiredOptions(false); 00356 } 00357 }
getLinks | ( | $ | product = null |
) |
Get downloadable product links
Mage_Catalog_Model_Product | $product |
Definition at line 44 of file Type.php.
00045 { 00046 $product = $this->getProduct($product); 00047 /* @var Mage_Catalog_Model_Product $product */ 00048 if (is_null($product->getDownloadableLinks())) { 00049 $_linkCollection = Mage::getModel('downloadable/link')->getCollection() 00050 ->addProductToFilter($product->getId()) 00051 ->addTitleToResult($product->getStoreId()) 00052 ->addPriceToResult($product->getStore()->getWebsiteId()); 00053 $linksCollectionById = array(); 00054 foreach ($_linkCollection as $link) { 00055 /* @var Mage_Downloadable_Model_Link $link */ 00056 00057 $link->setProduct($product); 00058 $linksCollectionById[$link->getId()] = $link; 00059 } 00060 $product->setDownloadableLinks($linksCollectionById); 00061 } 00062 return $product->getDownloadableLinks(); 00063 }
getLinkSelectionRequired | ( | $ | product = null |
) |
Check if product cannot be purchased with no links selected
Mage_Catalog_Model_Product | $product |
Definition at line 109 of file Type.php.
00110 { 00111 return $this->getProduct($product)->getLinksPurchasedSeparately(); 00112 }
getOrderOptions | ( | $ | product = null |
) |
Prepare additional options/information for order item which will be created from this product
Mage_Catalog_Model_Product | $product |
Reimplemented from Mage_Catalog_Model_Product_Type_Abstract.
Definition at line 317 of file Type.php.
00318 { 00319 $options = parent::getOrderOptions($product); 00320 if ($linkIds = $this->getProduct($product)->getCustomOption('downloadable_link_ids')) { 00321 $linkOptions = array(); 00322 $links = $this->getLinks($product); 00323 foreach (explode(',', $linkIds->getValue()) as $linkId) { 00324 if (isset($links[$linkId])) { 00325 $linkOptions[] = $linkId; 00326 } 00327 } 00328 $options = array_merge($options, array('links' => $linkOptions)); 00329 } 00330 $options = array_merge($options, array( 00331 'is_downloadable' => true, 00332 'real_product_type' => self::TYPE_DOWNLOADABLE 00333 )); 00334 return $options; 00335 }
getSamples | ( | $ | product = null |
) |
Get downloadable product samples
Mage_Catalog_Model_Product | $product |
Definition at line 120 of file Type.php.
00121 { 00122 $product = $this->getProduct($product); 00123 /* @var Mage_Catalog_Model_Product $product */ 00124 if (is_null($product->getDownloadableSamples())) { 00125 $_sampleCollection = Mage::getModel('downloadable/sample')->getCollection() 00126 ->addProductToFilter($product->getId()) 00127 ->addTitleToResult($product->getStoreId()); 00128 $product->setDownloadableSamples($_sampleCollection); 00129 } 00130 00131 return $product->getDownloadableSamples(); 00132 }
getSearchableData | ( | $ | product = null |
) |
Retrieve additional searchable data from type instance Using based on product id and store_id data
Mage_Catalog_Model_Product | $product |
Reimplemented from Mage_Catalog_Model_Product_Type_Abstract.
Definition at line 366 of file Type.php.
00367 { 00368 $searchData = parent::getSearchableData($product); 00369 $product = $this->getProduct($product); 00370 00371 $linkSearchData = Mage::getSingleton('downloadable/link') 00372 ->getSearchableData($product->getId(), $product->getStoreId()); 00373 if ($linkSearchData) { 00374 $searchData = array_merge($searchData, $linkSearchData); 00375 } 00376 00377 $sampleSearchData = Mage::getSingleton('downloadable/sample') 00378 ->getSearchableData($product->getId(), $product->getStoreId()); 00379 if ($sampleSearchData) { 00380 $searchData = array_merge($searchData, $sampleSearchData); 00381 } 00382 00383 return $searchData; 00384 }
hasLinks | ( | $ | product = null |
) |
Check if product has links
Mage_Catalog_Model_Product | $product |
Definition at line 71 of file Type.php.
00072 { 00073 return count($this->getLinks($product)) > 0; 00074 }
hasOptions | ( | $ | product = null |
) |
Check if product has options
Mage_Catalog_Model_Product | $product |
Reimplemented from Mage_Catalog_Model_Product_Type_Abstract.
Definition at line 82 of file Type.php.
00083 { 00084 //return true; 00085 return $this->getProduct($product)->getLinksPurchasedSeparately() 00086 || parent::hasOptions($product); 00087 }
hasRequiredOptions | ( | $ | product = null |
) |
Check if product has required options
Mage_Catalog_Model_Product | $product |
Reimplemented from Mage_Catalog_Model_Product_Type_Abstract.
Definition at line 95 of file Type.php.
00096 { 00097 if (parent::hasRequiredOptions($product) || $this->getProduct($product)->getLinksPurchasedSeparately()) { 00098 return true; 00099 } 00100 return false; 00101 }
hasSamples | ( | $ | product = null |
) |
Check if product has samples
Mage_Catalog_Model_Product | $product |
Definition at line 140 of file Type.php.
00141 { 00142 return count($this->getSamples($product)) > 0; 00143 }
prepareForCart | ( | Varien_Object $ | buyRequest, | |
$ | product = null | |||
) |
Enter description here...
Varien_Object | $buyRequest | |
Mage_Catalog_Model_Product | $product |
Reimplemented from Mage_Catalog_Model_Product_Type_Abstract.
Definition at line 275 of file Type.php.
00276 { 00277 $result = parent::prepareForCart($buyRequest, $product); 00278 00279 if (is_string($result)) { 00280 return $result; 00281 } 00282 // if adding product from admin area we add all links to product 00283 if ($this->getProduct($product)->getSkipCheckRequiredOption()) { 00284 $this->getProduct($product)->setLinksPurchasedSeparately(false); 00285 } 00286 $preparedLinks = array(); 00287 if ($this->getProduct($product)->getLinksPurchasedSeparately()) { 00288 if ($links = $buyRequest->getLinks()) { 00289 foreach ($this->getLinks($product) as $link) { 00290 if (in_array($link->getId(), $links)) { 00291 $preparedLinks[] = $link->getId(); 00292 } 00293 } 00294 } 00295 } else { 00296 foreach ($this->getLinks($product) as $link) { 00297 $preparedLinks[] = $link->getId(); 00298 } 00299 } 00300 if ($preparedLinks) { 00301 $this->getProduct($product)->addCustomOption('downloadable_link_ids', implode(',', $preparedLinks)); 00302 return $result; 00303 } 00304 if ($this->getLinkSelectionRequired($product)) { 00305 return Mage::helper('downloadable')->__('Please specify product link(s).'); 00306 } 00307 return $result; 00308 }
save | ( | $ | product = null |
) |
Enter description here...
Mage_Catalog_Model_Product | $product |
Reimplemented from Mage_Catalog_Model_Product_Type_Abstract.
Definition at line 151 of file Type.php.
00152 { 00153 parent::save($product); 00154 00155 $product = $this->getProduct($product); 00156 /* @var Mage_Catalog_Model_Product $product */ 00157 00158 if ($data = $product->getDownloadableData()) { 00159 if (isset($data['sample'])) { 00160 $_deleteItems = array(); 00161 foreach ($data['sample'] as $sampleItem) { 00162 if ($sampleItem['is_delete'] == '1') { 00163 if ($sampleItem['sample_id']) { 00164 $_deleteItems[] = $sampleItem['sample_id']; 00165 } 00166 } else { 00167 unset($sampleItem['is_delete']); 00168 if (!$sampleItem['sample_id']) { 00169 unset($sampleItem['sample_id']); 00170 } 00171 $sampleModel = Mage::getModel('downloadable/sample'); 00172 $files = array(); 00173 if (isset($sampleItem['file'])) { 00174 $files = Zend_Json::decode($sampleItem['file']); 00175 unset($sampleItem['file']); 00176 } 00177 00178 $sampleModel->setData($sampleItem) 00179 ->setSampleType($sampleItem['type']) 00180 ->setProductId($product->getId()) 00181 ->setStoreId($product->getStoreId()); 00182 00183 if ($sampleModel->getSampleType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) { 00184 $sampleFileName = Mage::helper('downloadable/file')->moveFileFromTmp( 00185 Mage_Downloadable_Model_Sample::getBaseTmpPath(), 00186 Mage_Downloadable_Model_Sample::getBasePath(), 00187 $files 00188 ); 00189 $sampleModel->setSampleFile($sampleFileName); 00190 } 00191 $sampleModel->save(); 00192 } 00193 } 00194 if ($_deleteItems) { 00195 Mage::getResourceModel('downloadable/sample')->deleteItems($_deleteItems); 00196 } 00197 } 00198 if (isset($data['link'])) { 00199 $_deleteItems = array(); 00200 foreach ($data['link'] as $linkItem) { 00201 if ($linkItem['is_delete'] == '1') { 00202 if ($linkItem['link_id']) { 00203 $_deleteItems[] = $linkItem['link_id']; 00204 } 00205 } else { 00206 unset($linkItem['is_delete']); 00207 if (!$linkItem['link_id']) { 00208 unset($linkItem['link_id']); 00209 } 00210 $files = array(); 00211 if (isset($linkItem['file'])) { 00212 $files = Zend_Json::decode($linkItem['file']); 00213 unset($linkItem['file']); 00214 } 00215 $sample = array(); 00216 if (isset($linkItem['sample'])) { 00217 $sample = $linkItem['sample']; 00218 unset($linkItem['sample']); 00219 } 00220 $linkModel = Mage::getModel('downloadable/link') 00221 ->setData($linkItem) 00222 ->setLinkType($linkItem['type']) 00223 ->setProductId($product->getId()) 00224 ->setStoreId($product->getStoreId()) 00225 ->setWebsiteId($product->getStore()->getWebsiteId()); 00226 if (null === $linkModel->getPrice()) { 00227 $linkModel->setPrice(0); 00228 } 00229 if ($linkModel->getIsUnlimited()) { 00230 $linkModel->setNumberOfDownloads(0); 00231 } 00232 $sampleFile = array(); 00233 if ($sample && isset($sample['type'])) { 00234 if ($sample['type'] == 'url' && $sample['url'] != '') { 00235 $linkModel->setSampleUrl($sample['url']); 00236 } 00237 $linkModel->setSampleType($sample['type']); 00238 $sampleFile = Zend_Json::decode($sample['file']); 00239 } 00240 if ($linkModel->getLinkType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) { 00241 $linkFileName = Mage::helper('downloadable/file')->moveFileFromTmp( 00242 Mage_Downloadable_Model_Link::getBaseTmpPath(), 00243 Mage_Downloadable_Model_Link::getBasePath(), 00244 $files 00245 ); 00246 $linkModel->setLinkFile($linkFileName); 00247 } 00248 if ($linkModel->getSampleType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) { 00249 $linkSampleFileName = Mage::helper('downloadable/file')->moveFileFromTmp( 00250 Mage_Downloadable_Model_Link::getBaseSampleTmpPath(), 00251 Mage_Downloadable_Model_Link::getBaseSamplePath(), 00252 $sampleFile 00253 ); 00254 $linkModel->setSampleFile($linkSampleFileName); 00255 } 00256 $linkModel->save(); 00257 } 00258 } 00259 if ($_deleteItems) { 00260 Mage::getResourceModel('downloadable/link')->deleteItems($_deleteItems); 00261 } 00262 } 00263 } 00264 00265 return $this; 00266 }
const TYPE_DOWNLOADABLE = 'downloadable' |