<?php
namespace MagePal\AdminSalesOrderViewButton\Plugin\Sales\Block\Adminhtml\Order;
use Magento\Sales\Block\Adminhtml\Order\View as OrderView;
class View
{
public function beforeSetLayout(OrderView $subject)
{
$subject->addButton(
'order_custom_button',
[
'label' => __('Add Product'),
'class' => __('add'),
'id' => 'add_new_product',
'onclick' => 'setLocation(".../catalog/product/new/set/4/type/simple/key/aa28309bce371172005ac8f5ec8533a866ec59cdc21014b3a7a9e8560a149d18/")'
]
);
}
}
?php namespace
Tigren\SapIntegration\Plugin\Sales\Block\Adminhtml\Order; use
Magento\Framework\UrlInterface; use
Magento\Framework\View\LayoutInterface; use
Magento\Sales\Block\Adminhtml\Order\View; class ViewPlugin
{
private $urlBuilder;
public function __construct(
UrlInterface $urlBuilder
) {
$this->urlBuilder = $urlBuilder;
}
public function beforeSetLayout(View $subject, LayoutInterface $layout)
{
$subject->addButton('sap_log_detail', [
'label' => __('SAP Log Detail'),
'class' => 'clone',
'id' => 'sap-log-detail',
'onclick' => 'setLocation(\'' . $this->getCloneUrl($subject->getOrderId()) . '\')'
]);
return [$layout];
}
private function getCloneUrl($orderId)
{
return $this->urlBuilder->getUrl(
'sap_integration/sapLog/LogDetail',
['order_id' => $orderId]
);
}
}
I am beginner in Yii Framework.I have created the _form.php with Yii widget CActiveForm.I have made the Checkbox list for week of days.I have serialized checkbox values on actioncreate and save into database table.Actually problem is that When i calling the actionupdate then my checked values are not showing that i have insert on actioncreate.actioncreate and actionupdate using the same form _form.php.
I have written my code below
actioncreate
public function actionCreate()
{
$model=new CustomerAccounts;
if(isset($_POST['CustomerAccounts']))
{
$model->attributes=$_POST['CustomerAccounts'];
$model->DateCreated = date('Y-m-d H:i:s');
$model->DeliveryDay = serialize($_POST['CustomerAccounts']['DeliveryDay']);
if($model->save()) {
Yii::app()->user->setFlash('success', 'Customer Account create successfully.');
$this->redirect(array('admin'));
} else {
Yii::app()->user->setFlash('danger','An error occurred. Please try again.');
}
}
$this->render('create',array(
'model'=>$model,
));
}
actionupdate
public function actionUpdate($id)
{
$model=$this->loadModel($id);
if(isset($_POST['CustomerAccounts']))
{
$model->attributes=$_POST['CustomerAccounts'];
$model->DeliveryDay = serialize($_POST['CustomerAccounts']['DeliveryDay']);
$model->DateCreated = date('Y-m-d H:i:s');
if($model->save()) {
Yii::app()->user->setFlash('success', 'Customer Account update successfully.');
$this->redirect(array('admin'));
} else {
Yii::app()->user->setFlash('danger','An error occurred. Please try again.');
}
}
$this->render('update',array(
'model'=>$model,
));
}
_form.php
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'customer-accounts-form',
'enableAjaxValidation'=>false,
<div class="row">
<div class="col-lg-12" style="padding-left: 34px;">
<?php echo $form->labelEx($model, 'DeliveryDay'); ?>
<?php echo $form->error($model, 'DeliveryDay'); ?>
<div id="checkbox" style="padding-left: 90px;">
<?php
$htmlOptions = array('template' => '<tr><td >{input}</td> <td> {label}</td> </tr', 'multiple' => true, 'checked' => 'checked');
echo $form->checkBoxList($model, 'DeliveryDay', Yii::app()->params['WeekDays'], $htmlOptions);
?>
</div></div></div>
<?php $this->endWidget(); ?>
Here my model
class CustomerAccounts extends CActiveRecord
{
public function tableName()
{
return 'customer_accounts';
}
public function rules()
{
return array(
array('DeliveryDay, Status, CustomerID, Employee_ID, PaymentModeID', 'required'),
array('CustomerID, Employee_ID, PaymentModeID, PcBottle, Bottle6Ltr, Bottle1500Ml, Bottle500Ml, TabStand, Pump, DispensirStatus, PCBottlesQuantity, PCBottleSecurity, DispensirQuantity, DispensirSerialNo, DispensirSecurity, TotalAmount, Status', 'numerical', 'integerOnly'=>true),
array('DateJoin', 'length', 'max'=>250),
array('Description', 'safe'),
array('CustomerAccountID, CustomerID, Employee_ID, PaymentModeID, DateJoin, PcBottle, Bottle6Ltr, Bottle1500Ml, Bottle500Ml, TabStand, Pump, DispensirStatus, PCBottlesQuantity, PCBottleSecurity, DispensirQuantity, DispensirSerialNo, DispensirSecurity, TotalAmount, DeliveryDay, Description, Status, DateCreated', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
'customer' => array(self::BELONGS_TO, 'Customer', 'CustomerID'),
'employee' => array(self::BELONGS_TO, 'Employee', 'Employee_ID'),
'paymentMode' => array(self::BELONGS_TO, 'PaymentMods', 'PaymentModeID'),
);
}
public function attributeLabels()
{
return array(
'CustomerAccountID' => 'Customer Account',
'CustomerID' => 'Customer',
//'Employee_ID' => 'Employee',
'Employee_ID' => 'Sale Person',
'PaymentModeID' => 'Payment Mode',
'DateJoin' => 'Date Join',
'PcBottle' => 'Pc Bottle',
'Bottle6Ltr' => 'Bottle6 Ltr',
'Bottle1500Ml' => 'Bottle1500 Ml',
'Bottle500Ml' => 'Bottle500 Ml',
'TabStand' => 'Tab Stand',
'Pump' => 'Pump',
'DispensirStatus' => 'Dispensir Status',
'PCBottlesQuantity' => 'Pcbottles Quantity',
'PCBottleSecurity' => 'Pcbottle Security',
'DispensirQuantity' => 'Dispensir Quantity',
'DispensirSerialNo' => 'Dispensir Serial No',
'DispensirSecurity' => 'Dispensir Security',
'TotalAmount' => 'Total Amount',
'DeliveryDay' => 'Delivery Day',
'Description' => 'Description',
'Status' => 'Status',
'DateCreated' => 'Date Created',
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('CustomerAccountID',$this->CustomerAccountID);
$criteria->compare('CustomerID',$this->CustomerID);
$criteria->compare('Employee_ID',$this->Employee_ID);
$criteria->compare('PaymentModeID',$this->PaymentModeID);
$criteria->compare('DateJoin',$this->DateJoin,true);
$criteria->compare('PcBottle',$this->PcBottle);
$criteria->compare('Bottle6Ltr',$this->Bottle6Ltr);
$criteria->compare('Bottle1500Ml',$this->Bottle1500Ml);
$criteria->compare('Bottle500Ml',$this->Bottle500Ml);
$criteria->compare('TabStand',$this->TabStand);
$criteria->compare('Pump',$this->Pump);
$criteria->compare('DispensirStatus',$this->DispensirStatus);
$criteria->compare('PCBottlesQuantity',$this->PCBottlesQuantity);
$criteria->compare('PCBottleSecurity',$this->PCBottleSecurity);
$criteria->compare('DispensirQuantity',$this->DispensirQuantity);
$criteria->compare('DispensirSerialNo',$this->DispensirSerialNo);
$criteria->compare('DispensirSecurity',$this->DispensirSecurity);
$criteria->compare('TotalAmount',$this->TotalAmount);
$criteria->compare('DeliveryDay',$this->DeliveryDay,true);
$criteria->compare('Description',$this->Description,true);
$criteria->compare('Status',$this->Status);
$criteria->compare('DateCreated',$this->DateCreated,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
Would anyone Can tell me when i call the actionupdate How the checked values will be shows from database table ?
You have to unserialized checkbox values afterFind() function in your model file (i.e. models/CustomerAccounts.php) as follows:
public function afterFind() {
$this->DeliveryDay = unserialize($this->DeliveryDay);
parent::afterFind();
}
i want to build a update profile page, and i have 2 mysql table 1. account 2. info, so i want to insert or update the user info table.
this is what i have so far, but its return an error when saving the data "Call to undefined method stdClass::save()"
controller:
public function actionUpdate_profile() {
$model = new UserProfileForm();
$user = Userinfo::model()->findByPk(Yii::app()->user->id);
$model->name = $user->_name;
$model->myurl = $user->myurl;
if (isset($_POST['UserProfileForm'])) {
$model->attributes = $_POST['UserProfileForm'];
if ($model->validate()) {
$model->attributes = $_POST['UserProfileForm'];
$user->name = $model->name;
$user->myurl = $model->myurl;
$user->save();
});
});
$this->render('update_profile', array(
'model' => $model,
'user' => $user,
));
}
model:
class Userinfo extends CActiveRecord {
public static function model($className = __CLASS__) {
return parent::model($className);
}
public function tableName() {
return 'user_info';
}
public function rules() {
return array(
array('email, name, myurl', 'length', 'max' => 255),
);
}
public function attributeLabels() {
return array(
'user_id' => Yii::t('yii', 'Id User'),
'name' => Yii::t('yii', 'First Name'),
'myurl' => Yii::t('yii', 'Last Name'),
);
}
class UserProfileForm extends CFormModel {
public $name;
public $myurl;
public function rules() {
return array(
array('name, myurl', 'required'),
);
}
public function attributeLabels() {
return array(
'name' => Yii::t('yii', 'First Name'),
'myurl' => Yii::t('yii', 'Last Name'),
);
}
}
I know this not best practice but it is concise -
if($user = Userinfo::model()->findByPk(Yii::app()->user->id)) {
//then work with $user here
}
I have overridden the Mage_Adminhtml_Block_Sales_Order_Grid to add additionl 3 columns as follows.
Customer Email
Payment Type
Products ordered
My extended grid class is as follows.
<?php
class Wowmall_ExtendedGrid_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
protected function _getCollectionClass()
{
return 'sales/order_grid_collection';
}
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()
->joinLeft('sales_flat_order_payment', 'main_table.entity_id = sales_flat_order_payment.parent_id','method')
->join('customer_entity', 'main_table.customer_id = customer_entity.entity_id','email')
->join('sales_flat_order_item', 'main_table.entity_id = sales_flat_order_item.order_id','name')->distinct(true);
$collection->getSelect()->group('main_table.entity_id');
$this->setCollection($collection);
return $this;
}
protected function _prepareColumns()
{
// rest code...
$this->addColumn('email', array(
'header' => Mage::helper('sales')->__('Customer Email'),
'index' => 'email',
'type' => 'text',
));
$this->addColumn('method', array(
'header' => Mage::helper('sales')->__('Payment Type'),
'index' => 'method',
'type' => 'options',
'options' => array('verisign' => 'Credit Card', 'checkmo' => 'Check', 'purchaseorder' => 'Purchase Order'),
));
$this->addColumn('name', array(
'header' => Mage::helper('sales')->__('Product(s) Ordered'),
'index' => 'name',
'type' => 'text',
));
// rest code...
But the pagination is not working. All the records are loading in a single page.
Please any suggestions?
Found the solution.
The issue occurred due to the following statement.
$collection->getSelect()->group('main_table.entity_id');
I edited the lib/Varien/Data/Collection/Db.php
My Db.php file located in app/code/local/Varien/Data/Collection/Db.php
Following is the code.
.....//rest code
public function getSelectCountSql()
{
$this->_renderFilters();
$countSelect = clone $this->getSelect();
$countSelect->reset(Zend_Db_Select::ORDER);
$countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
$countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
$countSelect->reset(Zend_Db_Select::COLUMNS);
if(count($this->getSelect()->getPart(Zend_Db_Select::GROUP)) > 0) {
$countSelect->reset(Zend_Db_Select::GROUP);
$countSelect->distinct(true);
$group = $this->getSelect()->getPart(Zend_Db_Select::GROUP);
$countSelect->columns("COUNT(DISTINCT ".implode(", ", $group).")");
} else {
$countSelect->columns('COUNT(*)');
}
return $countSelect;
}
....//rest code
Then after clearing the cache and session it worked .. :)
I have a problem that i can`t get throught.
I am trying to display information from relational table like this:
$dataProvider = PartnerSite::model()->with('siteCommercials')->findAll("user_id=" . Yii::app()->user->id);
$this->render('index', array(
'dataProvider' => $dataProvider,
'allMoney' => 1
));
But in my view i am seeing that error:
Relation "siteCommercials" is not defined in active record class "PartnerSite".
But the fact is that my model have relation:
public function relations() {
return array(
'goesFromSites' => array(self::HAS_MANY, 'GoesFromSite', 'site_id'),
'user' => array(self::BELONGS_TO, 'User', 'user_id'),
'siteCommercials' => array(self::HAS_MANY, 'SiteCommercial', 'site_id'),
);
}
So my question is. Is there is something wrong? I can't get it... In only one that model is a lot of problems... BeforeSave() doesn't work and relations work not well. User relation is working just fine.
Full listing of "model":
<?php
abstract class BasePartnerSite extends GxActiveRecord {
public $siteCommercials = "oke";
public static function model($className=__CLASS__) {
return parent::model($className);
}
public function tableName() {
return '{{partner_site}}';
}
public static function label($n = 1) {
return Yii::t('app', 'PartnerSite|PartnerSites', $n);
}
public static function representingColumn() {
return 'site_name';
}
public function rules() {
return array(
array('site_name', 'required'),
array('user_id', 'numerical', 'integerOnly'=>true),
array('site_name', 'length', 'max'=>255),
array('id, site_name, user_id', 'safe', 'on'=>'search'),
);
}
public function relations() {
return array(
'goesFromSites' => array(self::HAS_MANY, 'GoesFromSite', 'site_id'),
'user' => array(self::BELONGS_TO, 'User', 'user_id'),
'siteCommercials' => array(self::HAS_MANY, 'SiteCommercial', 'site_id'),
);
}
public function pivotModels() {
return array(
);
}
public function attributeLabels() {
return array(
'id' => Yii::t('app', 'ID'),
'site_name' => Yii::t('app', 'Site Name'),
'user_id' => null,
'goesFromSites' => null,
'user' => null,
'siteCommercials' => null,
);
}
public function search() {
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id);
$criteria->compare('site_name', $this->site_name, true);
$criteria->compare('user_id', $this->user_id);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
}
Your class is BasePartnerSite. In this class you define relation siteCommercials.
Your error message: "Relation "siteCommercials" is not defined in active record class "PartnerSite".
So then shouldn't your code be?
$dataProvider = BasePartnerSite::model()->with('siteCommercials')->findAll("user_id=" . Yii::app()->user->id);