00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Collection
00036 extends Mage_Core_Model_Mysql4_Collection_Abstract
00037 {
00038 protected $_product;
00039 protected $_linkModel;
00040 protected $_linkTypeId;
00041
00042 protected function _construct()
00043 {
00044 $this->_init('catalog/product_link');
00045 }
00046
00047
00048
00049
00050
00051
00052
00053 public function setLinkModel($linkModel)
00054 {
00055 $this->_linkModel = $linkModel;
00056 if ($linkModel->getLinkTypeId()) {
00057 $this->_linkTypeId = $linkModel->getLinkTypeId();
00058 }
00059 return $this;
00060 }
00061
00062
00063
00064
00065
00066
00067 public function getLinkModel()
00068 {
00069 return $this->_linkModel;
00070 }
00071
00072
00073
00074
00075
00076
00077
00078 public function setProduct($product)
00079 {
00080 $this->_product = $product;
00081 return $this;
00082 }
00083
00084
00085
00086
00087
00088
00089 public function getProduct()
00090 {
00091 return $this->_product;
00092 }
00093
00094
00095
00096
00097
00098
00099 public function addLinkTypeIdFilter()
00100 {
00101 if ($this->_linkTypeId) {
00102 $this->addFieldToFilter("link_type_id", $this->_linkTypeId);
00103 }
00104 return $this;
00105 }
00106
00107
00108
00109
00110
00111
00112 public function addProductIdFilter()
00113 {
00114 if ($this->getProduct() && $this->getProduct()->getId()) {
00115 $this->addFieldToFilter("product_id", $this->getProduct()->getId());
00116 }
00117 return $this;
00118 }
00119
00120
00121
00122
00123
00124
00125 public function joinAttributes()
00126 {
00127 if ($this->getLinkModel()) {
00128 $attributes = $this->getLinkModel()->getAttributes();
00129 $attributesByType = array();
00130 foreach ($attributes as $attribute) {
00131 $table = $this->getLinkModel()->getAttributeTypeTable($attribute['type']);
00132 $alias = 'link_attribute_'.$attribute['code'].'_'.$attribute['type'];
00133 $this->getSelect()->joinLeft(
00134 array($alias => $table),
00135 $alias.'.link_id=main_table.link_id AND '.$alias.'.product_link_attribute_id='.$attribute['id'],
00136 array($attribute['code'] => 'value')
00137 );
00138 }
00139 }
00140 return $this;
00141 }
00142 }