Skip to content

Instantly share code, notes, and snippets.

@sthamann
Last active October 19, 2017 00:39
Show Gist options
  • Save sthamann/5310948 to your computer and use it in GitHub Desktop.
Save sthamann/5310948 to your computer and use it in GitHub Desktop.
Shopware 4 - Add 2 new colums to Order-Model & fill them through order process
<?php
/**
* Shopware 4.0
* Copyright © 2012 shopware AG
*
* According to our dual licensing model, this program can be used either
* under the terms of the GNU Affero General Public License, version 3,
* or under a proprietary license.
*
* The texts of the GNU Affero General Public License with an additional
* permission and of our proprietary license can be found at and
* in the LICENSE file you have received along with this program.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* "Shopware" is a registered trademark of shopware AG.
* The licensing of the program under the AGPLv3 does not imply a
* trademark license. Therefore any rights, title and interest in
* our trademarks remain entirely with us.
*
* @category Shopware
* @package Shopware_Plugins
* @subpackage AdvancedMenu
* @copyright Copyright (c) 2012, shopware AG (http://www.shopware.de)
* @version $Id$
* @author Heiner Lohaus
* @author $Author$
*/
/**
* Shopware AdvancedMenu Plugin
*
* todo@all: Documentation
*/
class Shopware_Plugins_Frontend_SwagTestCases_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
/**
* Install plugin method
*
* @return bool
*/
public function install()
{
// Add 2 new columns to s_order_attributes
Shopware()->Models()->addAttribute('s_order_attributes','myPrx','Test1','varchar(255)', false, 0);
Shopware()->Models()->addAttribute('s_order_attributes','myPrx','Test2','varchar(255)', false, 0);
$metaDataCache = Shopware()->Models()->getConfiguration()->getMetadataCacheImpl();
$metaDataCache->deleteAll();
Shopware()->Models()->generateAttributeModels(
array('s_order_attributes')
);
$this->subscribeEvent('Shopware_Modules_Order_SendMail_FilterVariables','OnBeforeSendOrderConfirmation');
return array('success' => true, 'invalidateCache' => array('backend', 'proxy'));
}
public function OnBeforeSendOrderConfirmation (Enlight_Event_EventArgs $args){
$orderVariables = $args->getReturn();
$ordernumber = $orderVariables["ordernumber"];
// Find order id by order number
$order = Shopware()->Models()->getRepository('Shopware\Models\Order\Order')->findOneBy(array('number'=>$ordernumber));
$orderAttributeModel = Shopware()->Models()->getRepository('Shopware\Models\Attribute\Order')->findOneBy(
array("orderId"=>$order->getId()));
if ($orderAttributeModel instanceof \Shopware\Models\Attribute\Order){
$orderAttributeModel->setMyPrxTest1("Test");
$orderAttributeModel->setMyPrxTest2("Test2");
Shopware()->Models()->persist($orderAttributeModel);
Shopware()->Models()->flush();
}
$args->setReturn($orderVariables);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment