ProductVariation_OrderItem::ProductVariation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
4
class ProductVariation_OrderItem extends Product_OrderItem
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
{
6
7
    // ProductVariation Access Function
8
    public function ProductVariation($current = false)
9
    {
10
        return $this->Buyable($current);
11
    }
12
13
    /**
14
     * @decription: we return the product name here -
15
     * leaving the Table Sub Title for the name of the variation
16
     *
17
     * @return String - title in cart.
18
     */
19
    public function TableTitle()
20
    {
21
        return $this->getTableTitle();
22
    }
23
    public function getTableTitle()
24
    {
25
        $tableTitle = _t("Product.UNKNOWN", "Unknown Product");
26
        if ($variation = $this->ProductVariation()) {
27
            if ($product = $variation->Product()) {
28
                $tableTitle = $product->Title;
29
            }
30
        }
31
        $extendedTitle = $this->extend('updateTableTitle', $tableTitle);
32
        if ($extendedTitle !== null && is_array($extendedTitle) && count($extendedTitle)) {
33
            return implode("", $extendedTitle);
34
        }
35
36
        return $tableTitle;
37
    }
38
39
    /**
40
     * we return the product variation name here
41
     * the Table Title will return the name of the Product.
42
     * @return String - sub title in cart.
43
     **/
44
    public function TableSubTitle()
45
    {
46
        return $this->getTableSubTitle();
47
    }
48
    public function getTableSubTitle()
49
    {
50
        $tableSubTitle = _t("Product.VARIATIONNOTFOUND", "Variation Not Found");
51
        if ($variation = $this->ProductVariation()) {
52
            if ($variation->exists()) {
53
                $tableSubTitle = $variation->getTitle(true, true);
0 ignored issues
show
Unused Code introduced by
The call to DataObject::getTitle() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
54
            }
55
        }
56
        $extendedSubTitle = $this->extend('updateTableSubTitle', $tableSubTitle);
57
        if ($extendedSubTitle !== null && is_array($extendedSubTitle) && count($extendedSubTitle)) {
58
            return implode("", $extendedSubTitle);
59
        }
60
        return $tableSubTitle;
61
    }
62
63
64
    /**
65
     * Check if this variation is new - that is, if it has yet to have been written
66
     * to the database.
67
     *
68
     * @return boolean True if this is new.
69
     */
70
    public function isNew()
71
    {
72
        /**
73
         * This check was a problem for a self-hosted site, and may indicate a
74
         * bug in the interpreter on their server, or a bug here
75
         * Changing the condition from empty($this->ID) to
76
         * !$this->ID && !$this->record['ID'] fixed this.
77
         */
78
        if (empty($this->ID)) {
79
            return true;
80
        }
81
        if (is_numeric($this->ID)) {
82
            return false;
83
        }
84
        return stripos($this->ID, 'new') === 0;
85
    }
86
}
87