Esempio n. 1
0
 /**
  * @param $id
  * @return ProductLink
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = ProductLink::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('StoreModule.store', 'Page not found!'));
     }
     return $model;
 }
Esempio n. 2
0
 /**
  * Связывает продукты
  * @param $product Product|int Ид продукта или продукт
  * @param null $type_id Тип связи
  * @return bool
  */
 public function link($product, $type_id = null)
 {
     $link = new ProductLink();
     $link->product_id = $this->id;
     $link->linked_product_id = $product instanceof Product ? $product->id : $product;
     $link->type_id = $type_id;
     return $link->save();
 }
Esempio n. 3
0
<?php

/* @var $searchModel ProductSearch */
/* @var $product Product */
$linkTypes = ProductLinkType::getFormattedList();
?>


<div class="row">
    <div class="col-sm-12">
        <h3><?php 
echo Yii::t('StoreModule.store', 'Products related with "{name}"', ['{name}' => $product->name]);
?>
</h3>
        <?php 
$linked = new ProductLink('search');
$linked->setAttributes(Yii::app()->getRequest()->getParam('ProductLink'));
$linked->product_id = $product->id;
$this->widget('yupe\\widgets\\CustomGridView', ['id' => 'linked-product-grid', 'type' => 'condensed', 'dataProvider' => $linked->search(), 'filter' => $linked, 'actionsButtons' => false, 'bulkActions' => [false], 'ajaxUrl' => ['/store/productBackend/update', 'id' => $product->id], 'columns' => [['type' => 'raw', 'value' => function ($data) {
    return CHtml::link(CHtml::image($data->linkedProduct->getImageUrl(40, 40), "", ["class" => "img-thumbnail"]), ["/store/productBackend/update", "id" => $data->linkedProduct->id]);
}], ['header' => Yii::t('StoreModule.store', 'Name'), 'type' => 'raw', 'value' => function ($data) {
    return CHtml::link($data->linkedProduct->name, ["/store/productBackend/update", "id" => $data->linkedProduct->id]);
}], ['header' => Yii::t('StoreModule.store', 'SKU'), 'type' => 'raw', 'value' => function ($data) {
    return CHtml::link($data->linkedProduct->sku, ["/store/productBackend/update", "id" => $data->linkedProduct->id]);
}], ['header' => Yii::t('StoreModule.store', 'Price'), 'type' => 'raw', 'value' => function ($data) {
    return $data->linkedProduct->price;
}], ['class' => 'yupe\\widgets\\EditableStatusColumn', 'name' => 'type_id', 'url' => $this->createUrl('/store/linkBackend/inline'), 'source' => $linkTypes, 'options' => []], ['class' => 'yupe\\widgets\\CustomButtonColumn', 'template' => '{delete}', 'buttons' => ['delete' => ['url' => function ($data) {
    return Yii::app()->createUrl('/store/linkBackend/delete', ['id' => $data->id]);
}]]]]]);
?>
    </div>
 private function readCSVLinks()
 {
     $row = 0;
     if (($handle = fopen("../mysite/code/links.csv", "r")) !== FALSE) {
         while (($link = fgetcsv($handle, 1000, ",")) !== FALSE) {
             $num = count($link);
             $row++;
             //      Debug::show($link);
             $prodOldIDL = $link[4];
             $linkPath = $link[1];
             $prod = DataObject::get("Product")->filter(array("OldID" => $prodOldIDL))->first();
             $linkSet = new ProductLink();
             if ($prod) {
                 $linkSet->Text = $link[3];
                 $linkSet->Text_sv = $link[2];
                 $linkSet->Link = $link[1];
                 $linkSet->write();
                 $prod->ProductLinks()->add($linkSet);
                 $prod->write();
             }
             Debug::show($linkSet);
             Debug::show("----------------------------------------");
         }
     }
 }