@@ -1,30 +1,30 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return array( |
| 4 | - 'name' => 'ai-client-html', |
|
| 5 | - 'depends' => array( |
|
| 6 | - 'aimeos-core', |
|
| 7 | - ), |
|
| 8 | - 'include' => array( |
|
| 9 | - 'client/html/src', |
|
| 10 | - 'controller/jobs/src', |
|
| 11 | - ), |
|
| 12 | - 'i18n' => array( |
|
| 13 | - 'client' => 'client/i18n', |
|
| 14 | - 'client/code' => 'client/i18n/code', |
|
| 15 | - 'client/country' => 'client/i18n/country', |
|
| 16 | - 'client/currency' => 'client/i18n/currency', |
|
| 17 | - 'client/language' => 'client/i18n/language', |
|
| 18 | - ), |
|
| 19 | - 'config' => array( |
|
| 20 | - 'client/html/config', |
|
| 21 | - ), |
|
| 22 | - 'custom' => array( |
|
| 23 | - 'client/html/templates' => array( |
|
| 24 | - 'client/html/templates', |
|
| 25 | - ), |
|
| 26 | - 'controller/jobs' => array( |
|
| 27 | - 'controller/jobs/src', |
|
| 28 | - ), |
|
| 29 | - ), |
|
| 4 | + 'name' => 'ai-client-html', |
|
| 5 | + 'depends' => array( |
|
| 6 | + 'aimeos-core', |
|
| 7 | + ), |
|
| 8 | + 'include' => array( |
|
| 9 | + 'client/html/src', |
|
| 10 | + 'controller/jobs/src', |
|
| 11 | + ), |
|
| 12 | + 'i18n' => array( |
|
| 13 | + 'client' => 'client/i18n', |
|
| 14 | + 'client/code' => 'client/i18n/code', |
|
| 15 | + 'client/country' => 'client/i18n/country', |
|
| 16 | + 'client/currency' => 'client/i18n/currency', |
|
| 17 | + 'client/language' => 'client/i18n/language', |
|
| 18 | + ), |
|
| 19 | + 'config' => array( |
|
| 20 | + 'client/html/config', |
|
| 21 | + ), |
|
| 22 | + 'custom' => array( |
|
| 23 | + 'client/html/templates' => array( |
|
| 24 | + 'client/html/templates', |
|
| 25 | + ), |
|
| 26 | + 'controller/jobs' => array( |
|
| 27 | + 'controller/jobs/src', |
|
| 28 | + ), |
|
| 29 | + ), |
|
| 30 | 30 | ); |
@@ -18,113 +18,113 @@ |
||
| 18 | 18 | * @subpackage Jobs |
| 19 | 19 | */ |
| 20 | 20 | class Standard |
| 21 | - extends \Aimeos\Controller\Jobs\Base |
|
| 22 | - implements \Aimeos\Controller\Jobs\Iface |
|
| 21 | + extends \Aimeos\Controller\Jobs\Base |
|
| 22 | + implements \Aimeos\Controller\Jobs\Iface |
|
| 23 | 23 | { |
| 24 | - private $client; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Returns the localized name of the job. |
|
| 29 | - * |
|
| 30 | - * @return string Name of the job |
|
| 31 | - */ |
|
| 32 | - public function getName() |
|
| 33 | - { |
|
| 34 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Customer account e-mails' ); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Returns the localized description of the job. |
|
| 40 | - * |
|
| 41 | - * @return string Description of the job |
|
| 42 | - */ |
|
| 43 | - public function getDescription() |
|
| 44 | - { |
|
| 45 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Sends e-mails for new customer accounts' ); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Executes the job. |
|
| 51 | - * |
|
| 52 | - * @throws \Aimeos\Controller\Jobs\Exception If an error occurs |
|
| 53 | - */ |
|
| 54 | - public function run() |
|
| 55 | - { |
|
| 56 | - $context = $this->getContext(); |
|
| 57 | - $queue = $context->getMessageQueue( 'mq-email', 'customer/email/account' ); |
|
| 58 | - $custManager = \Aimeos\MShop\Factory::createManager( $context, 'customer' ); |
|
| 59 | - |
|
| 60 | - while( ( $msg = $queue->get() ) !== null ) |
|
| 61 | - { |
|
| 62 | - if( ( $list = json_decode( $msg->getBody(), true ) ) !== null ) |
|
| 63 | - { |
|
| 64 | - $password = ( isset( $list['customer.password'] ) ? $list['customer.password'] : '' ); |
|
| 65 | - $item = $custManager->createItem(); |
|
| 66 | - $item->fromArray( $list ); |
|
| 67 | - |
|
| 68 | - $this->sendEmail( $context, $item, $password ); |
|
| 69 | - } |
|
| 70 | - else |
|
| 71 | - { |
|
| 72 | - $context->getLogger()->log( sprintf( 'Invalid JSON encode message: %1$s', $msg->getBody() ) ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $queue->del( $msg ); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Returns the product notification e-mail client |
|
| 82 | - * |
|
| 83 | - * @param \Aimeos\MShop\Context\Item\Iface $context Context item object |
|
| 84 | - * @return \Aimeos\Client\Html\Iface Product notification e-mail client |
|
| 85 | - */ |
|
| 86 | - protected function getClient( \Aimeos\MShop\Context\Item\Iface $context ) |
|
| 87 | - { |
|
| 88 | - if( !isset( $this->client ) ) |
|
| 89 | - { |
|
| 90 | - $templatePaths = $this->getAimeos()->getCustomPaths( 'client/html' ); |
|
| 91 | - $this->client = \Aimeos\Client\Html\Email\Account\Factory::createClient( $context, $templatePaths ); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $this->client; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Sends the account creation e-mail to the e-mail address of the customer |
|
| 100 | - * |
|
| 101 | - * @param \Aimeos\MShop\Context\Item\Iface $context Context item object |
|
| 102 | - * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object |
|
| 103 | - * @param string $password Customer clear text password |
|
| 104 | - */ |
|
| 105 | - protected function sendEmail( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Customer\Item\Iface $item, $password ) |
|
| 106 | - { |
|
| 107 | - $address = $item->getPaymentAddress(); |
|
| 108 | - |
|
| 109 | - $view = $context->getView(); |
|
| 110 | - $view->extAddressItem = $address; |
|
| 111 | - $view->extAccountCode = $item->getCode(); |
|
| 112 | - $view->extAccountPassword = $password; |
|
| 113 | - |
|
| 114 | - $helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $context->getI18n( $address->getLanguageId() ) ); |
|
| 115 | - $view->addHelper( 'translate', $helper ); |
|
| 116 | - |
|
| 117 | - $mailer = $context->getMail(); |
|
| 118 | - $message = $mailer->createMessage(); |
|
| 119 | - |
|
| 120 | - $helper = new \Aimeos\MW\View\Helper\Mail\Standard( $view, $message ); |
|
| 121 | - $view->addHelper( 'mail', $helper ); |
|
| 122 | - |
|
| 123 | - $client = $this->getClient( $context ); |
|
| 124 | - $client->setView( $view ); |
|
| 125 | - $client->getHeader(); |
|
| 126 | - $client->getBody(); |
|
| 127 | - |
|
| 128 | - $mailer->send( $message ); |
|
| 129 | - } |
|
| 24 | + private $client; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Returns the localized name of the job. |
|
| 29 | + * |
|
| 30 | + * @return string Name of the job |
|
| 31 | + */ |
|
| 32 | + public function getName() |
|
| 33 | + { |
|
| 34 | + return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Customer account e-mails' ); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Returns the localized description of the job. |
|
| 40 | + * |
|
| 41 | + * @return string Description of the job |
|
| 42 | + */ |
|
| 43 | + public function getDescription() |
|
| 44 | + { |
|
| 45 | + return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Sends e-mails for new customer accounts' ); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Executes the job. |
|
| 51 | + * |
|
| 52 | + * @throws \Aimeos\Controller\Jobs\Exception If an error occurs |
|
| 53 | + */ |
|
| 54 | + public function run() |
|
| 55 | + { |
|
| 56 | + $context = $this->getContext(); |
|
| 57 | + $queue = $context->getMessageQueue( 'mq-email', 'customer/email/account' ); |
|
| 58 | + $custManager = \Aimeos\MShop\Factory::createManager( $context, 'customer' ); |
|
| 59 | + |
|
| 60 | + while( ( $msg = $queue->get() ) !== null ) |
|
| 61 | + { |
|
| 62 | + if( ( $list = json_decode( $msg->getBody(), true ) ) !== null ) |
|
| 63 | + { |
|
| 64 | + $password = ( isset( $list['customer.password'] ) ? $list['customer.password'] : '' ); |
|
| 65 | + $item = $custManager->createItem(); |
|
| 66 | + $item->fromArray( $list ); |
|
| 67 | + |
|
| 68 | + $this->sendEmail( $context, $item, $password ); |
|
| 69 | + } |
|
| 70 | + else |
|
| 71 | + { |
|
| 72 | + $context->getLogger()->log( sprintf( 'Invalid JSON encode message: %1$s', $msg->getBody() ) ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $queue->del( $msg ); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Returns the product notification e-mail client |
|
| 82 | + * |
|
| 83 | + * @param \Aimeos\MShop\Context\Item\Iface $context Context item object |
|
| 84 | + * @return \Aimeos\Client\Html\Iface Product notification e-mail client |
|
| 85 | + */ |
|
| 86 | + protected function getClient( \Aimeos\MShop\Context\Item\Iface $context ) |
|
| 87 | + { |
|
| 88 | + if( !isset( $this->client ) ) |
|
| 89 | + { |
|
| 90 | + $templatePaths = $this->getAimeos()->getCustomPaths( 'client/html' ); |
|
| 91 | + $this->client = \Aimeos\Client\Html\Email\Account\Factory::createClient( $context, $templatePaths ); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $this->client; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Sends the account creation e-mail to the e-mail address of the customer |
|
| 100 | + * |
|
| 101 | + * @param \Aimeos\MShop\Context\Item\Iface $context Context item object |
|
| 102 | + * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object |
|
| 103 | + * @param string $password Customer clear text password |
|
| 104 | + */ |
|
| 105 | + protected function sendEmail( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Customer\Item\Iface $item, $password ) |
|
| 106 | + { |
|
| 107 | + $address = $item->getPaymentAddress(); |
|
| 108 | + |
|
| 109 | + $view = $context->getView(); |
|
| 110 | + $view->extAddressItem = $address; |
|
| 111 | + $view->extAccountCode = $item->getCode(); |
|
| 112 | + $view->extAccountPassword = $password; |
|
| 113 | + |
|
| 114 | + $helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $context->getI18n( $address->getLanguageId() ) ); |
|
| 115 | + $view->addHelper( 'translate', $helper ); |
|
| 116 | + |
|
| 117 | + $mailer = $context->getMail(); |
|
| 118 | + $message = $mailer->createMessage(); |
|
| 119 | + |
|
| 120 | + $helper = new \Aimeos\MW\View\Helper\Mail\Standard( $view, $message ); |
|
| 121 | + $view->addHelper( 'mail', $helper ); |
|
| 122 | + |
|
| 123 | + $client = $this->getClient( $context ); |
|
| 124 | + $client->setView( $view ); |
|
| 125 | + $client->getHeader(); |
|
| 126 | + $client->getBody(); |
|
| 127 | + |
|
| 128 | + $mailer->send( $message ); |
|
| 129 | + } |
|
| 130 | 130 | } |