Nccategory.php
6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* @package anc_album
* @category magento
* @mailto code [at] netz.coop
* @author netz.coop eG*
* @copyright (c) 2014, netz.coop eG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
class Anc_Album_Helper_Nccategory extends Mage_Core_Helper_Abstract {
/**
* gibt den request_path zurück,
* falls $param_ncalbum übergeben und 'core/url_rewrite' noch nicht exisitert wird diese in getUrlRewrite angelegt
*
* @param Mage_Catalog_Model_Category $param_ncalbumjokercategory
* @param array $param_ncalbum
* @return string - request_path
*/
public function getCategoryUrl (Mage_Catalog_Model_Category $param_ncalbumjokercategory, $param_ncalbum) {
// D::compareFe($param_ncalbumjokercategory, $param_ncalbum, '$param_ncalbumjokercategory, $param_ncalbum');
if(is_object($param_ncalbumjokercategory)) {
if(array_key_exists('url_rewrite', $param_ncalbum) && $param_ncalbum['url_rewrite']) {
$basepath = dirname($param_ncalbumjokercategory->getRequestPath());
$new_request_path = $basepath.'/'.$param_ncalbum['url_rewrite'].'.html';
return $this->getUrlRewrite($new_request_path, $param_ncalbumjokercategory);
} else if($param_ncalbumjokercategory->getParentId()
&& $param_ncalbumjokercategory->getParentCategory()->getName()==='ncalbumjokercategory') {
// $parent_url_rewrite = basename(Mage::app()->getRequest()->getOriginalPathInfo(), ".html");
$SelectedCategoryNcAlbumModel = $this->getSelectedCategoryNcAlbumModel();
if(is_object($SelectedCategoryNcAlbumModel)) {
$parent_url_rewrite = $SelectedCategoryNcAlbumModel->getUrlRewrite();
$ncalbum = Mage::getModel('anc_album/ncalbum')->load($parent_url_rewrite, 'url_rewrite');
if($ncalbum->getUrlRewrite() === $parent_url_rewrite) {
$new_request_path = str_replace("ncalbumjokercategory", $parent_url_rewrite, $param_ncalbumjokercategory->getRequestPath());
return $this->getUrlRewrite($new_request_path, $param_ncalbumjokercategory);
}
}
} else {
return $param_ncalbumjokercategory->getRequestPath();
}
}
}
private $SelectedCategoryNcAlbumModel = null;
private $SelectedCategoryNcAlbumModelByUrl = null;
public function getSelectedCategoryNcAlbumModel() {
$SelectedCategoryNcAlbumModel = Mage::getSingleton('checkout/session')->getSelectedCategoryNcAlbumModel();
// D::fe($SelectedCategoryNcAlbumModel, 'getSelectedCategoryNcAlbumModel');
return $SelectedCategoryNcAlbumModel;
}
/**
* return Anc_Album_Model_Ncalbum
*/
public function getSelectedCategoryNcAlbumModelByUrl() {
// umständlicher Vergleich zwischen current_category und getRequest
if(is_null($this->SelectedCategoryNcAlbumModelByUrl)) {
$current_category = Mage::registry('current_category');
if(is_object($current_category)
&& strpos($current_category->getUrlPath(), 'ncalbumjokercategory') !==false
&& Mage::app()->getRequest()->getParam('id') === $current_category->getId()
) {
$OriginalPathInfo = explode('/', Mage::app()->getRequest()->getOriginalPathInfo());
if(!$OriginalPathInfo[0]) {
array_shift($OriginalPathInfo);
}
$UrlPath = explode('/', $current_category->getUrlPath());
if(!$UrlPath[0]) {
array_shift($UrlPath);
}
if(array_search('ncalbumjokercategory', $UrlPath) !== false) {
$SelectedNcAlbumCategory = $OriginalPathInfo[array_search('ncalbumjokercategory', $UrlPath)];
} else if(array_search('ncalbumjokercategory.html', $UrlPath) !== false) {
$SelectedNcAlbumCategory = $OriginalPathInfo[array_search('ncalbumjokercategory.html', $UrlPath)];
$SelectedNcAlbumCategory = basename($SelectedNcAlbumCategory, ".html");
} else {
D::compareFe($OriginalPathInfo, $UrlPath, '$OriginalPathInfo, $UrlPath');
}
if($SelectedNcAlbumCategory) {
$ncalbum = Mage::getModel('anc_album/ncalbum')->load($SelectedNcAlbumCategory, 'url_rewrite');
if(is_object($ncalbum) && $ncalbum->getId()) {
$this->SelectedCategoryNcAlbumModelByUrl = $ncalbum;
}
}
} else {
$current_product = Mage::registry('current_product');
// D::comparefe($current_product, 'no $current_category!!!!',1,1);
}
}
if(!$this->SelectedCategoryNcAlbumModelByUrl) {
// D::li('Achtung keine $this->SelectedCategoryNcAlbumModelByUrl = $ncalbum; !!! ',1,1);
}
return $this->SelectedCategoryNcAlbumModelByUrl;
}
/**
* schaut nach ob schon exisitert, falls nein wirds erstellt
* und gibt dann den richtigen (durch anc_album/ncalbum.url_rewrite ersetzten) request_path zurück
*
* @param string $new_request_path
* @param Mage_Catalog_Model_Category $param_ncalbumjokercategory
* @return string - request_path
*/
private function getUrlRewrite($new_request_path, Mage_Catalog_Model_Category $param_ncalbumjokercategory) {
$already_url_rewrite = Mage::getModel('core/url_rewrite')->load($new_request_path, 'request_path');
if($already_url_rewrite->getRequestPath() === $new_request_path) {
return $already_url_rewrite->getRequestPath();
} else {
$url_rewrite = Mage::getModel('core/url_rewrite')->load($param_ncalbumjokercategory->getRequestPath(), 'request_path');
$new_url_rewrite = Mage::getModel('core/url_rewrite');
$new_url_rewrite->setRequestPath($new_request_path);
$new_url_rewrite->setStoreId($url_rewrite->getStoreId());
$new_url_rewrite->setIdPath(str_replace('.html', '', $new_request_path));
$new_url_rewrite->setTargetPath($url_rewrite->getTargetPath());
$new_url_rewrite->setOptions($url_rewrite->getOptions());
$new_url_rewrite->setDescription($url_rewrite->getDescription());
$new_url_rewrite->setCategoryId($url_rewrite->getCategoryId());
$new_url_rewrite->setProductId($url_rewrite->getProductId());
$new_url_rewrite->save();
$new_url_rewrite = Mage::getModel('core/url_rewrite')->load($new_request_path, 'request_path');
return $new_url_rewrite->getRequestPath();
}
}
}