Issues (258)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Subscribers/TemplateExtension.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * (c) shopware AG <[email protected]>
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace ShopwarePlugins\Connect\Subscribers;
9
10
use Enlight\Event\SubscriberInterface;
11
use Shopware\Connect\SDK;
12
use ShopwarePlugins\Connect\Components\Helper;
13
use ShopwarePlugins\Connect\Components\ConfigFactory;
14
use ShopwarePlugins\Connect\Components\Utils\ConnectOrderUtil;
15
16
/**
17
 * Loads various template extensions
18
 *
19
 * Class TemplateExtension
20
 * @package ShopwarePlugins\Connect\Subscribers
21
 */
22
class TemplateExtension implements SubscriberInterface
23
{
24
    /**
25
     * @var SDK
26
     */
27
    private $sdk;
28
29
    /**
30
     * @var Helper
31
     */
32
    private $helper;
33
34
    /**
35
     * @param SDK $sdk
36
     * @param Helper $helper
37
     */
38
    public function __construct(SDK $sdk, Helper $helper)
39
    {
40
        $this->sdk = $sdk;
41
        $this->helper = $helper;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public static function getSubscribedEvents()
48
    {
49
        return [
50
            'Enlight_Controller_Action_PostDispatch_Backend_Order' => 'onPostDispatchBackendOrder',
51
            'Enlight_Controller_Action_PostDispatch_Frontend_Detail' => 'addConnectTemplateVariablesToDetail',
52
        ];
53
    }
54
55
    /**
56
     * Extends the order backend module in order to show a special hint for connect products
57
     *
58
     * @param \Enlight_Event_EventArgs $args
59
     */
60 View Code Duplication
    public function onPostDispatchBackendOrder(\Enlight_Event_EventArgs $args)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62
        /** @var $subject \Enlight_Controller_Action */
63
        $subject = $args->getSubject();
64
        $request = $subject->Request();
65
66
        switch ($request->getActionName()) {
67
            case 'load':
68
                $subject->View()->extendsTemplate(
69
                    'backend/order/view/connect.js'
70
                );
71
72
                $subject->View()->extendsTemplate(
73
                    'backend/order/controller/connect_main.js'
74
                );
75
76
                break;
77
78
            case 'getList':
79
                $subject->View()->data = $this->markConnectOrders(
80
                    $subject->View()->data
81
                );
82
83
                break;
84
85
            default:
86
                break;
87
        }
88
    }
89
90
    /**
91
     * Mark Orders as Connect Orders for view purposes.
92
     *
93
     * @param array $data
94
     * @return array
95
     */
96
    private function markConnectOrders($data)
97
    {
98
        $orderIds = array_map(function ($orderView) {
99
            return (int) $orderView['id'];
100
        }, $data);
101
102
        if (!$orderIds) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $orderIds of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
103
            return $data;
104
        }
105
106
        $connectOrderData = [];
107
108
109
        $connectOrderUtil = new ConnectOrderUtil();
110
        $result = $connectOrderUtil->getRemoteConnectOrders($orderIds);
111
112
        foreach ($result as $connectOrder) {
113
            $connectOrderData[$connectOrder['orderID']] = $connectOrder;
114
        }
115
116
        $result = $connectOrderUtil->getLocalConnectOrders($orderIds);
117
118
        foreach ($result as $connectOrder) {
119
            $connectOrderData[$connectOrder['orderID']] = $connectOrder;
120
        }
121
122
        if (!$connectOrderData) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $connectOrderData of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
123
            return $data;
124
        }
125
126
        $shopNames = [];
127
128
        foreach ($data as $idx => $order) {
129
            if (! isset($connectOrderData[$order['id']])) {
130
                continue;
131
            }
132
133
            $result = $connectOrderData[$order['id']];
134
135
            $data[$idx]['connectShopId'] = $result['connect_shop_id'];
136
            $data[$idx]['connectOrderId'] = $result['connect_order_id'];
137
138
            if (!isset($shopNames[$result['connect_shop_id']])) {
139
                $shopNames[$result['connect_shop_id']] = $this->sdk->getShop($result['connect_shop_id'])->name;
140
            }
141
142
            $data[$idx]['connectShop'] = $shopNames[$result['connect_shop_id']];
143
        }
144
145
        return $data;
146
    }
147
148
    /**
149
     * Event listener method for the frontend detail page. Will add connect template variables if the current product
150
     * is a connect product.
151
     *
152
     * @event Enlight_Controller_Action_PostDispatch_Frontend_Detail
153
     * @param \Enlight_Event_EventArgs $args
154
     */
155
    public function addConnectTemplateVariablesToDetail(\Enlight_Event_EventArgs $args)
156
    {
157
        /** @var $action \Enlight_Controller_Action */
158
        $action = $args->getSubject();
159
        $view = $action->View();
160
161
        $articleData = $view->getAssign('sArticle');
162
        if (empty($articleData['articleID'])) {
163
            return;
164
        }
165
166
        if ($this->helper->isRemoteArticleDetail($articleData['articleDetailsID']) === false) {
167
            return;
168
        }
169
170
        $shopProductId = $this->helper->getShopProductId($articleData['articleDetailsID']);
171
        $products = $this->helper->getRemoteProducts([$shopProductId->sourceId], $shopProductId->shopId);
172
173
        if (empty($products)) {
174
            return;
175
        }
176
177
        $product = reset($products);
178
        if (empty($product->shopId)) {
179
            return;
180
        }
181
182
        // Fix prices for displaying
183
        foreach (['price', 'purchasePrice', 'vat'] as $name) {
184
            $product->$name = round($product->$name, 2);
185
        }
186
187
        $shop = $this->sdk->getShop($product->shopId);
188
189
        /** @var \ShopwarePlugins\Connect\Components\Config $configComponent */
190
        $configComponent = ConfigFactory::getConfigInstance();
191
        $view->assign([
192
            'connectProduct' => $product,
193
            'connectShop' => $shop,
194
            'connectShopInfo' => $configComponent->getConfig('detailShopInfo'),
195
            'connectNoIndex' => $configComponent->getConfig('detailProductNoIndex'),
196
        ]);
197
    }
198
}
199