| Conditions | 5 |
| Paths | 9 |
| Total Lines | 27 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 30 | public function setCanonical() |
||
| 31 | { |
||
| 32 | $get = Yii::$app->request->get(); |
||
| 33 | $setCanonical = false; |
||
| 34 | |||
| 35 | foreach ($this->labels as $label) { |
||
| 36 | if (array_key_exists($label, $get)) { |
||
| 37 | unset($get[$label]); |
||
| 38 | $setCanonical = true; |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | if ($setCanonical) { |
||
| 43 | $get[0] = '/' . Yii::$app->controller->getRoute(); |
||
| 44 | if ('/' . Yii::$app->requestedAction->controller->route === Yii::getAlias('@product')) { |
||
| 45 | $get['model'] = Product::findById(Yii::$app->request->get('model_id')); |
||
| 46 | unset($get['model_id']); |
||
| 47 | } |
||
| 48 | $this->owner->view->registerLinkTag( |
||
| 49 | [ |
||
| 50 | 'rel' => 'canonical', |
||
| 51 | 'href' => Url::toRoute($get, true) |
||
| 52 | ] |
||
| 53 | ); |
||
| 54 | |||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 |