Back to PhocacartCart class

Method updateShipping

public
updateShipping
()

Method updateShipping - Source code

/*
 * Check if after update shipping and payment method is still valid
 * If not remove it
 * If set in parameter to yes, remove it even it is valid
 */
public function updateShipping()
{
    $paramsC = PhocacartUtils::getComponentParameters();
    $change_remove_shipping_method = $paramsC->get('change_remove_shipping_method', 1);
    $currentShippingId = isset($this->shipping['id']) && $this->shipping['id'] > 0 ? (int) $this->shipping['id'] : 0;
    if ($this->pos && (int) $this->vendor->id > 0) {
        $typeUser = 0;
    } else {
        if ((int) $this->user->id > 0) {
            $typeUser = 0;
        } else {
            $typeUser = 1;
        }
    }
    // $change_remove_shipping_method is not a POS parameter
    // In POS we don't remove shpping or payment a priori but we always validate it
    if (!$this->pos && $change_remove_shipping_method == 1) {
        PhocacartShipping::removeShipping($typeUser);
        return;
    }
    if (!isset($this->total[0])) {
        $this->total[0] = array();
    }
    $isValidShipping = false;
    $shippingObject = new PhocacartShipping();
    $shippingObject->setType($this->type);
    if ($currentShippingId > 0) {
        $isValidShipping = $shippingObject->checkAndGetShippingMethod((int) $currentShippingId, $this->total[0]);
    }
    if (!$isValidShipping) {
        PhocacartShipping::removeShipping($typeUser);
    }
}