Skip to content

Instantly share code, notes, and snippets.

@MihailoJoksimovic
Created February 18, 2014 15:15
Show Gist options
  • Save MihailoJoksimovic/9072899 to your computer and use it in GitHub Desktop.
Save MihailoJoksimovic/9072899 to your computer and use it in GitHub Desktop.
private function getAddToCartPanel() {
$mainDiv = Ext::create('container');
$addToCartTextLabel = Ext::create('label');
$addToCartTextLabel->setText('To Cart:');
$addToCartTextLabel->setStyle('font-weight:bold; font-size: 16px; padding-left: 5px;');
$addToCartTextLabel->appendTo($mainDiv);
$addToCartButtonAndText = Ext::create('fieldcontainer');
$addToCartButtonAndText->setConfigByIndex('layout', array(
'type' => 'hbox',
'pack' => 'end',
));
$addToCartButtonAndText->setStyle('margin-top: 3px');
$addToCartButtonAndText->appendTo($mainDiv);
$textField = $this->getFormFactory()->makeTextfield();
$textField->setId('article_qty');
$textField->setWidth(90);
$textField->setPadding(2);
$textField->setEmptyText('Quantity');
$textField->appendTo($addToCartButtonAndText);
$displayField = Ext::create('displayfield');
$displayField->setConfigByIndex('value', "PCE");
$displayField->setMargin("0 5");
$displayField->appendTo($addToCartButtonAndText);
$addToCartButton = $this->getButtonFactory()->makeButton();
$articleId = $this->getArticle()->getId();
$successTitle = $this->translate('success');
$successText = $this->translate('article_added_to_cart');
$failureTitle = $this->translate('failure');
$failureText = $this->translate('unable_to_add_article_to_cart');
$btnHandler =<<<js
addToCartBtnHandler = function(){
var qty = Ext.getCmp('article_qty').getValue();
var success = function(){
Ext.Msg.alert('$successTitle', '$successText');
};
var failure = function(){
Ext.Msg.alert('$failureTitle', '$failureText');
};
var callback = function(){
Ext.getCmp('$this->pageId').setLoading(false);
};
Ext.getCmp('$this->pageId').setLoading(true);
addArticleToCart($articleId, qty, {
success: success,
failure: failure,
callback: callback
});
}
js;
$addToCartButton->setHandler(Ext::createFn($btnHandler));
$addToCartButton->setConfigByIndex('icon', '/style/air/images/folder_cart.gif');
$addToCartButton->appendTo($addToCartButtonAndText);
return $mainDiv;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment