1 | <?php |
||
5 | class FrontendEnabled |
||
6 | { |
||
7 | /* |
||
8 | * After insert/update of a productuom, |
||
9 | * check all uoms belonging to that product, |
||
10 | * if any productuom is enabled, enable the product, |
||
11 | * otherwise, disable it. |
||
12 | * |
||
13 | */ |
||
14 | |||
15 | public function insertProductUom($e) |
||
16 | { |
||
17 | $dbResult = $e->getParam('result'); |
||
18 | if (!count($dbResult)) { |
||
19 | return; //no rows affected |
||
20 | } |
||
21 | |||
22 | $productId = is_array($e->getParam('data')) |
||
23 | ? $e->getParam('data')['product_id'] |
||
24 | : $e->getParam('data')->getProductId(); |
||
25 | $productService = $e->getTarget()->getProductService(); |
||
26 | $find = array('product_id' => $productId); |
||
27 | $product = $productService->find($find, array('uoms')); |
||
28 | |||
29 | $enabled = $this->canProductBeEnabled($product); |
||
30 | |||
31 | $productService->setEnabledProduct($productId, $enabled); |
||
32 | } |
||
33 | |||
34 | public function updateProductUom($e) |
||
35 | { |
||
36 | $productUomService = $e->getTarget(); |
||
37 | $productService = $productUomService->getProductService(); |
||
38 | |||
39 | $where = $e->getParam('where'); |
||
40 | $uoms = $productUomService->findRows($where); |
||
41 | |||
42 | $ids = array(); |
||
43 | foreach ($uoms as $uom) { |
||
44 | $ids[$uom['product_id']] = $uom['product_id']; |
||
45 | } |
||
46 | $products = $productService->getProductsById($ids); |
||
47 | |||
48 | foreach ($products as $product) { |
||
49 | $productService->populate($product, array('uoms')); |
||
50 | $row = array( |
||
51 | 'product_id' => $productId, |
||
|
|||
52 | 'enabled' => $this->canProductBeEnabled($product) |
||
53 | ); |
||
54 | $where = array('product_id' => $productId); |
||
55 | $productService->update($row, $where); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | public function canProductBeEnabled($product) |
||
71 | |||
72 | /* |
||
73 | * After insert/update of product(s), |
||
74 | * find any choices that reference the product, |
||
75 | * if the product is enabled, enable the choice, |
||
76 | * otherwise, disable it. |
||
77 | * |
||
78 | */ |
||
79 | |||
80 | public static function updateProduct($e) |
||
99 | |||
100 | public static function insertProduct($e) |
||
120 | } |
||
121 |
This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.
The variable may have been renamed without also renaming all references.