Example #1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     $itemPropClass = Kiwi::getItemPropClass();
     if ($this->categoryId) {
         $this->itemProps = $itemPropClass::getItemProps($this->categoryId);
     }
     if ($this->itemId) {
         $itemPropValueClass = Kiwi::getItemPropValueClass();
         $this->itemPropValues = $itemPropValueClass::getItemPropValues($this->itemId);
         if (!$this->categoryId) {
             $itemClass = Kiwi::getItemClass();
             $this->categoryId = $itemClass::getItem($this->itemId)->category_id;
             $this->itemProps = $itemPropClass::getItemProps($this->categoryId);
         }
         foreach ($this->itemProps as $key => $itemProp) {
             if (isset($this->itemPropValues[$key])) {
                 $itemPropValue = $this->itemPropValues[$key];
                 switch ($itemProp->type) {
                     case $itemPropClass::ITEM_PROP_TYPE_TEXT:
                         $this->setAttribute($key, $itemPropValue->custom_prop_value);
                         break;
                     case $itemPropClass::ITEM_PROP_TYPE_SELECT:
                         $this->setAttribute($key, $itemPropValue->prop_value_id);
                         break;
                     case $itemPropClass::ITEM_PROP_TYPE_CHECKBOX:
                         $this->setAttribute($key, array_keys((array) $itemPropValue));
                         break;
                     default:
                         break;
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * Finds the Item model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return \yincart\item\models\Item the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     $itemClass = Kiwi::getItemClass();
     if (($model = $itemClass::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #3
0
 public function attachEvents()
 {
     $itemClass = Kiwi::getItemClass();
     Event::on($itemClass, $itemClass::EVENT_INIT, function ($event) {
         /** @var \yincart\item\models\Item $item */
         $item = $event->sender;
         $item->attachBehavior('category', Kiwi::getCategoryBehaviorClass());
         $item->attachBehavior('tag', Kiwi::getTagBehaviorClass());
     });
 }
Example #4
0
 public function getItem()
 {
     return $this->hasOne(Kiwi::getItemClass(), ['item_id' => 'item_id']);
 }
Example #5
0
 public function getItems()
 {
     return $this->hasMany(Kiwi::getItemClass(), ['item_id' => 'item_id'])->via('itemCategories');
 }
Example #6
0
    <ol class="breadcrumb">
        <li><a href="<?php 
echo Url::to(['site/index']);
?>
">首页</a></li>
        <li class="active"><?php 
echo htmlspecialchars(Yii::$app->request->get('name'));
?>
</li>
    </ol>
    <!-- Product List Display Starts -->
    <div class="row">
        <!-- Product #1 Starts -->
        <?php 
foreach ($itmTreeModels as $itmTreeModel) {
    $itemClass = Kiwi::getItemClass();
    $item = $itemClass::findOne($itmTreeModel->item_id);
    $pictures = explode(',', $item->pictures);
    $itemUrl = Yii::$app->urlManager->createUrl(['item/view', 'id' => $item->item_id]);
    ?>
            <div class="col-md-4 col-sm-6">
                <div class="product-col">
                    <div class="image thumbnail" >
                        <a href="<?php 
    echo $itemUrl;
    ?>
"><img width="221" height="221" src="<?php 
    echo is_array($pictures) ? $pictures[0] : $pictures;
    ?>
" alt="product" class="img-responsive" /></a>
                    </div>